|
Split file using awk
I am trying to read a file and split the file into multiple files. I need to create new files with different set of lines from the original file. ie, the first output file may contain 10 lines and the second 100 lines and so on. The criteria is to get the lines between two lines starting with some characters(variable)
eg. A sample input file
DOC100
aaaaaa
bbbbbb
cccccccc
END
DOC200
ddddddd
eeeeeee
END
I need to send the lines between DOC100 and END to out.1
and lines between DOC200 and the next END to out.2
I thought I could do this using awk and I tried the following command but it didn't work.
k=grep DOC $filename|cut -c4-6
awk -v cn=$k '/DOC$cn/,/END/ { print $0 }' $filename >$outfile
Can anyone help me on this? Thanks
|