sed - copying every nth line to a new line -
i have txt file need copy 1st line of every 4 lines , print onto 3rd line of every four. , print new txt file. e.g
@cr5sm:00004:00029 ttttctctttctttctt + >>>/>@99419baaabb @cr5sm:00005:00026 attatagagggatag + ;969999999-4;bb
change this:
@cr5sm:00004:00029 ttttctctttctttctt +cr5sm:00004:00029 >>>/>@99419baaabb @cr5sm:00005:00026 attatagagggatag +cr5sm:00005:00026 ;969999999-4;bb
i have tried using awk cant seem find correct commands this. have solutions? thanks
using awk
:
$ awk '/^@/{a=substr($0,2)}/^\+/{$0=$0 a}1' file @cr5sm:00004:00029 ttttctctttctttctt +cr5sm:00004:00029 >>>/>@99419baaabb @cr5sm:00005:00026 attatagagggatag +cr5sm:00005:00026 ;969999999-4;bb
you can redirect output file saying:
awk '/^@/{a=substr($0,2)}/^\+/{$0=$0 a}1' file > newfile
- we use
substr
function capture lines start@
second character onwards until end of line. - we lines start
+
(notice escape since meta-character). once find line, append our captured line existing line. 1
@ end allows print lines.
Comments
Post a Comment