for i in table1 table2 table3 table4
do
perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat
done

what does perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat mean?

Edited 3 Years Ago by happygeek: fixed formatting

The experts here will correct and berate me if I am wrong, but while I don't under stand what the

[B]'s/ *\|/\|/g;[/B]

code means, the entire line of

[B]perl -ne 's/ *\|/\|/g; print' ${AHS_DATA}/${i} > ./${i}.dat [/B]

Appears to calculate the variable AHS_DATA divided by the variable i and outputs the result to i.dat...
This statement:

[B]'s/ *\|/\|/g;[/B]

appears to be some formatting instructions, but don't take my word on it...

-n means suppress output (i.e. read the lines in the file, but don't output them). s/ *\|/\|/g; means replace all occurrences of of zero or more whitespace followed ba a "|" (i.e. "|", or " |", or " |") with "|" .

And the print after that means output the lines where the "command" actually did anything (i.e. any line that did not have any occurrences of "|" will not be output). ${AHS_DATA} is a variable holding a directory name. ${i} is the variable from the loop (table1 or table2 or table3 etc), and references a file of that name in the above directory. sed will read this file for the "lines" of input referenced above. > ./${i}.dat means that all output should go into a file in the currect directory called table1.dat (or table2.dat , or table3.dat , etc, depending on the value of ${i} )

This article has been dead for over six months. Start a new discussion instead.