Add and number blank line above each line in a file

Gooze_Berry

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

Arkadiusz Drabczyk

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Number of same line in each text file

분류에서Dev

add / at the end of each line

분류에서Dev

Bash - pair each line of file

분류에서Dev

Why C program prints blank line to file?

분류에서Dev

How to add new line in a file

분류에서Dev

sort lines according to number of fields in each line

분류에서Dev

How to append number at the beginning of each line [PHP]?

분류에서Dev

How to count the number of a specific character in each line?

분류에서Dev

Add a line below each line matching a pattern only if not already present

분류에서Dev

Frequency of specific symbols on each line of a text file

분류에서Dev

Grep last N characters of each line in a file

분류에서Dev

Select line with empty line above and under

분류에서Dev

Add prefix and suffix to every line in a .txt file

분류에서Dev

add hash to a file using command line

분류에서Dev

Add (prepend) line to file, if parameter is not already existing

분류에서Dev

xslt - for each - line-by-line

분류에서Dev

Vim: Replace first word on each line of selection with number in list

분류에서Dev

How to Read string from file and compare to each line of second file

분류에서Dev

vim - split line by comma and add prefix to each token

분류에서Dev

remove characters from a list and add a line break from each element

분류에서Dev

Add text to beginning and end of each line using batch/cmd

분류에서Dev

Reading file nodeJS (from_Line number to end of file)

분류에서Dev

replace lines in the original file from another file by line number

분류에서Dev

Find a string in a file and then find the first line above containing another string with bash

분류에서Dev

file.each_line can only be called once

분류에서Dev

Command Line, File Name for each script executed. SQL

분류에서Dev

Write first 10 characters of each line to new file using bash

분류에서Dev

Sort words on each line, editing the file in-place

분류에서Dev

spread a file into multiple .csv files per each line of inputfile read

Related 관련 기사

  1. 1

    Number of same line in each text file

  2. 2

    add / at the end of each line

  3. 3

    Bash - pair each line of file

  4. 4

    Why C program prints blank line to file?

  5. 5

    How to add new line in a file

  6. 6

    sort lines according to number of fields in each line

  7. 7

    How to append number at the beginning of each line [PHP]?

  8. 8

    How to count the number of a specific character in each line?

  9. 9

    Add a line below each line matching a pattern only if not already present

  10. 10

    Frequency of specific symbols on each line of a text file

  11. 11

    Grep last N characters of each line in a file

  12. 12

    Select line with empty line above and under

  13. 13

    Add prefix and suffix to every line in a .txt file

  14. 14

    add hash to a file using command line

  15. 15

    Add (prepend) line to file, if parameter is not already existing

  16. 16

    xslt - for each - line-by-line

  17. 17

    Vim: Replace first word on each line of selection with number in list

  18. 18

    How to Read string from file and compare to each line of second file

  19. 19

    vim - split line by comma and add prefix to each token

  20. 20

    remove characters from a list and add a line break from each element

  21. 21

    Add text to beginning and end of each line using batch/cmd

  22. 22

    Reading file nodeJS (from_Line number to end of file)

  23. 23

    replace lines in the original file from another file by line number

  24. 24

    Find a string in a file and then find the first line above containing another string with bash

  25. 25

    file.each_line can only be called once

  26. 26

    Command Line, File Name for each script executed. SQL

  27. 27

    Write first 10 characters of each line to new file using bash

  28. 28

    Sort words on each line, editing the file in-place

  29. 29

    spread a file into multiple .csv files per each line of inputfile read

뜨겁다태그

보관