sed/awk: Three consecutive blank lines in a file, how to delete two of them?
I've spent a stupidly long amount of time trying to figure this out. I think at this point I'm losing braincells instead of gaining knowledge.
Like the subject says, I have a file with three consecutive blank lines. I want to delete two and keep one. Also, if anyone could direct me towards a guide on regular expressions particularly as they apply to sed, I would be grateful. I am having a hell of a time figuring out the syntax. :scratch: |
Hi,
Sed one-liners That link also has an answer to your question: Quote:
Feed your search engine with Sed and Regular Expression, you get a ton of hits. If a book is your thing then I would suggest O'Reilly's Sed & AWK. Hope this helps. |
If you have awk pointing at gawk, the following can work:
Code:
awk 'gsub(/\n\n\n/,"\n")' RS="\0" file |
Quote:
Code:
awk 'BEGIN { RS="\0" } { gsub(/\n\n\n/,"\n")}' file |
Quote:
You can also do other variables like FS after as well ;) |
I don't know, maybe it would work. Haven't tried it.
|
Quote:
|
Code:
$ awk -v myvar='it works!' 'BEGIN {print myvar}' test.sh |
hmmm ... so your pointing out that you didn't read my post!!
In either post do I talk about setting user defined variables? No If you care to review the awk manuals easily found on the net you will see that the awk internal variables, such as FS or RS, can be set post the action and pattern string, eg: Code:
awk '{print NF} FS=":" file using the BEGIN{} setting. Hopefully this will help you learn a little more about awk. |
All times are GMT -5. The time now is 02:21 PM. |