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' fileExplanation:
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.
hi
ReplyDeleteThis was good.
You can look Complete awk command tutorial here
Thanks