I am using the following command to output a list of servers with associated IPs. For another part of my script, I need this output to be formatted in a particular manner. With an incrementing line number above each line. Example below
paste <(aws ec2 describe-instances --query 'Reservations[*].Instances[*].Tags[*].{Name:Value}' --output text) \
<(aws ec2 describe-instances --query 'Reservations[*].Instances[*].{PrivateIP:PrivateIpAddress}' --output text) | awk 'ORS="\n\n"' >> $TMP1
Which outputs ( in a tmp file ) :
Dev Server 111.11.11.11
Test Server 222.22.22.22
However how can I append numbers to each blank line like so?
Example
1
Dev Server 111.11.11.11
2
Test Server 222.22.22.22
Use awk
:
$ cat FILE
Dev Server 111.11.11.11
Test Server 222.22.22.22
$ awk '{ if ($0 ~ /^$/) { print ++counter } else { print $0 }}' FILE
1
Dev Server 111.11.11.11
2
Test Server 222.22.22.22
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다