Link to home
Start Free TrialLog in
Avatar of shyam78
shyam78

asked on

awk help needed

i need a awk script that searches for commas in every row of the text file and replaces the comma with colon and the sets the field delimiter as comma.

cheers
shyam
 
Avatar of Nisus091197
Nisus091197

Hi,

sed will do it for you very easily:

sed -e 's/,/:/g' input.txt > output.txt

where input.txt is the file with all the commas and output.txt is the output file.

Regards, Nisus
http://www.omnimodo.com
to set the field delimiter to comma in awk add BEGIN { FS=","} as the first awk command, for example...

echo "test this, 1, 2, 3" | awk ' BEGIN { FS=","} {print $2}'

awk -F, 'BEGIN{OFS=":";ORS=","}{gsub(",",":");print}' file
# works with gawk only (probably mawk too)
Avatar of shyam78

ASKER

thanks guys.
the query helped to get rid of comma inside every column values.
(ie commas where inside the column values...

but the main thing that i want is to get comma as the delimiter for every column in the row.
at present the delimiter is tab.


ASKER CERTIFIED SOLUTION
Avatar of Nisus091197
Nisus091197

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
sed -e 's/,/:/g' input.txt > tmp.txt
sed -e 's/ /,/g' tmp.txt > output.txt

             
note that, you need to press <TAB> at the second sed command  s/<TAB>/,/g
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by Nisus

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer