I want to split one file input.tab
into two separate ones, odd lines to input_reads1.txt
, even lines to input_reads2.txt
for a serial of files with similar name pattern. Also I want to "match" input/output file names to keep consistency of file name:
CSEL_02.0_input.tab
CSEL_03.4_input.tab
CSEL_04.9_input.tab
CSEL_05.6_input.tab
CSEL_06.6_input.tab
CSEL_11.0_input.tab
CSEL_18.0_input.tab
......
One example:
CSEL_02.0_input.tab
seq1_description CAATCGATCGACTAG
seq2_description GTCGATCGACTAGGA
seq3_description CTCGATCGACTAGCT
seq4_description CGATCGCGCGGGGAA
Outputs file names and contents are:
CSEL_02.0_reads_R1.txt
seq1_description
CAATCGATCGACTAG
seq3_description
CTCGATCGACTAGCT
CSEL_02.0_reads_R2.txt
seq2_description
GTCGATCGACTAGGA
seq4_description
CGATCGCGCGGGGAA
I have tried:
for i in 02.0 03.4 04.9 05.6 06.6 11.0 18.0; do
awk -v stem=CSEL_${i}_reads_R '{print $1"\n"$2 >> "stem"(NR%2?1:2)".txt"}' CSEL_${i}_input.tab
done
But I got:
stem1.txt
stem2.txt
Shell variable "stem" did not expand as I want to match input/output file names.
What did I miss?