i have a file and would like to copy some entries that satisfy certain conditions.
For example
myfile
chr1 a b c
chr2 a b c
chr3 x y z
I would like to copy lines whose first column starts with chr1 and i want to copy it n times.
myfile
chr1 a b c
chr1 a b c
chr1 a b c
chr2 a b c
chr3 x y z
Something like this would be fine?
awk '{if ($1 == "chr1"){print; print;} print;}'It will print 2 more times the lines that start with
chr1…and with a for loop:
awk '{if ($1 == "chr1"){ for(i=1;i<=2;i++){ print; } } print;}'ok, this should be it
given a file named “conditions” like this:
and your example (with chr1, chr2 etc on different lines) as an input
it’ll print the chr1 line 6 times, the chr2 line 4 times and the chr3 line 1 time