Joining lines using Awk
Let's say I have a input file which looks like below:Apr 24 2014; is; a; sample; ; Jun 24 2014 123; may 25 2014; is; b; sample; ; Dec 21 2014 987I want to merge 6 lines at a time. Which means my output should look like:
Apr 24 2014;is;a;sample;;Jun 24 2014 123 may 25 2014;is;b;sample;;Dec 21 2014 987Below is a simple command that I would use:
awk '{ORS=(NR%6?"":RS)}1' file
Explanation:By doing,
ORS=(NR%6?"":RS)I am setting the output record separator to actual record separator only if line number is a multiple of 6.
.png)







I am a software programmer working in India. I usually like to blog in my free time.
hi
ReplyDeleteThis was good.
You can look Complete awk command tutorial here
Thanks