Double space a file using awk
Dear all,
I want to explore the unix awk command. The following one liner will generate the double space in a file: awk '1;{print " "}' < file.txt Can anybody please explain the use of "1;" in this command. Thank you very much in advance. |
Hi,
In this case the 1 prints the currently read line (try: awk '1' < file.txt). You can also use either of these to accomplish the same: Code:
awk '{print $0} ;{print " "}' < file.txt |
Thank you very much dear Druuna :)
|
Probably easiest to just set record separator:
Code:
awk 'ORS="\n\n"' file |
Quote:
|
To be more specific, the default action for any true statement is to print the line. Since any number other than zero evaluates as being true, using "1" as a command acts as a quick shortcut for typing "print".
By the way, the command as given above doesn't just double-space the file. the "blank" lines actually have one space in them. You probably want to tell it to print nothing instead. Code:
awk '1;{print ""}' file.txt Code:
awk '{print $0"\n"}' file.txt http://www.catonmat.net/blog/awk-one...ined-part-one/ |
Well seeing we are all having another look ... have we considered what happens with current solutions should the input line be blank?
I believe a better solution is: Code:
awk 'ORS=(NF)?"\n\n":""' file |
All times are GMT -5. The time now is 08:23 AM. |