Link to home
Start Free TrialLog in
Avatar of GAUTAM
GAUTAMFlag for United States of America

asked on

Unix command doubt

Hi Experts...
Can anyone explain this unix command bit-by-bit.
Please help...
Unix Command:
sed '/^$/d' $csv_file | egrep -v '(^,|^ )' | nawk -F "," '{OFS="|";print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15}' | nawk -F "|" '{i=1; while(i<=NF) {if ($i=="") {printf (" |")} else {printf ("%s|",$i)}; i++}; printf("\n")}' | sed 's/|$//'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The "nawk" command in the middle prints out each field, replacing empty fields (i.e. zero-length ones) with a single space.

A shorter version, assuming that all of the lines you want are 15 fields long, might be
grep '^[^, ]' $csv_file | sed -e 's/,,/, ,/g' -e 's/,$/, /' | tr , '|'

Open in new window

Can you provide the sample data of your csv file.


Avatar of GAUTAM

ASKER

@ALL:Thank you for your replies.

@itkamaraj:The sample file is attached.
sample.xls
The file is not in a CSV format, it needs to be converted to a csv for the script to work.
save the document as CSV.