Hi,
I need to insert a new line containing the string "QUERY" above every 5 lines.
The below piece of code inserts a new line after every 5th line
awk '{print $0} !(NR%5) {print "QUERY"}'
sed 'n;n;n;n;G;' --> I do not know how to give "QUERY" string here
But I need to insert it before every 5th line.
Hi
awk '!(NR%5) {print "QUERY"} {print $0}' file
Guru.
Wow, that works fine !! How to make the sed to work?
Hi
sed 'n;n;n;n;s/.*/QUERY\n&/;' file
Guru.
1 Like
Some sed do not know \n in the replacement part:
sed 'n;n;n;n;s/^/QUERY\
/' infile
sed 'n;n;n;n;i\
query\
' infile
--
GNU sed:
sed '0~5s/^/QUERY\n/' infile
1 Like