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
cheers
shyam
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}'
echo "test this, 1, 2, 3" | awk ' BEGIN { FS=","} {print $2}'
awk -F, 'BEGIN{OFS=":";ORS=","}{gs ub(",",":" );print}' file
# works with gawk only (probably mawk too)
# works with gawk only (probably mawk too)
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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
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