Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

awk help needed

Posted on 2003-02-19
8
Medium Priority
?
866 Views
Last Modified: 2013-12-26
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
 
0
Comment
Question by:shyam78
7 Comments
 
LVL 5

Expert Comment

by:Nisus091197
ID: 7985726
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
0
 
LVL 1

Expert Comment

by:brains
ID: 7986728
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}'

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7987071
awk -F, 'BEGIN{OFS=":";ORS=","}{gsub(",",":");print}' file
# works with gawk only (probably mawk too)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:shyam78
ID: 7990011
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.


0
 
LVL 5

Accepted Solution

by:
Nisus091197 earned 200 total points
ID: 7997533
Hi,

You change the delimiter of awk by using the -F paramater.

example:

text file, mmm, containing "1,2,3,4,5,6"

$ awk -F, '{print $3}' mmm
3
$

Nisus
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8017858
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
0
 
LVL 18

Expert Comment

by:liddler
ID: 9826957
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question