Hi,
I have source file where in the data is in the following format.
01,America,0001,AUH
03,F,F ,001,000,012,000
04,F,F ,023,000,012,000
03,F,A ,002,005,012,005,Y
04,F,A ,023,000,012,000,000
03,F,R ,003,007,007,007,Y,002
04,F,R ,023,000,007,002,002,002
03,F,O ,004,000,000,000,Y,003
04,F,O ,023,000,000,000,000
01,EGYPT,0001,AUH
03,F,F ,001,001,012,001,Y...
For fun, a Perl option:
Code:
perl -ple 'if (m/^01/) { $loc = (split /,/)[1] } else { $_ = "$_,$loc" }' file
More awk -ishly Perl:
Code:
perl -F, -plae 'if ($F[0] == '01') { $loc = $F[1] } else { $_ = "$_,$loc" }' file
(I like the first version better since it only splits the '01' lines, and in a big file that might amount to a significant difference.)
Hi, I have source file where in the data is in the following format. 01,America,0001,AUH 03,F,F ,001,000,012,000 04,F,F ,023,000,012,000 03,F,A ,002,005,012,005,Y 04,F,A ,023,000,012,000,000 03,F,R ,003,007,007,007,Y,002 04,F,R ,023,000,007,002,002,002 03,F,O ,004,000,000,000,Y,003 04,F,O ,023,000,000,000,000 01,EGYPT,0001,AUH 03,F,F ,001,001,012,001,Y 04,F,F ,023,000,012,001,001 01,SPAIN,0001,AUH 03,F,A ,021,000,012,000 04,F,F...
For fun, a Perl option: Code: perl -ple 'if (m/^01/) { $loc = (split /,/)[1] } else { $_ = "$_,$loc" }' file More awk -ishly Perl: Code: perl -F, -plae 'if ($F[0] == '01') { $loc = $F[1] } else { $_ = "$_,$loc" }' file (I like the first version better since it only splits the '01' lines, and in a big file that might amount to a significant difference.)
Thread profile page for "Append value of a row to subsequent rows" on http://www.linuxquestions.org.
This report page is a snippet summary view from a single thread "Append value of a row to subsequent rows", located on the Message Board at http://www.linuxquestions.org.
This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity