awk problem for commaseperated file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk problem for commaseperated file
# 1  
Old 05-06-2009
awk problem for commaseperated file

I have a commaseperated file. If data in a field has comma then the field is enclosed with double quotes as shown below

Quote:
CSV file
filed1,field2,field3
ABC,"hello,world",time
ABC,"hello,america",time1
XYZ,"god,bless",time2
INJ,are,youthere
Code:
awk -F, '{print $1,$2}' file

output i am getting:
Quote:
filed1 field2
ABC "hello
ABC "hello
XYZ "god
INJ are
output i want:
Quote:
filed1,field2
ABC,"hello,world"
ABC,"hello,america"
XYZ,"god,bless"
INJ,are

Basically i want to ignore commas with in double quotes.
Appreciate your help.
# 2  
Old 05-06-2009
Please start using the Forum 'Search' engines - many of your recently asked questions have been answered many times over.
For example, typing 'CSV+awk+vgersh99' in the 'Google UNIX.COM' search (in the upper right corner) will bring you plenty of relevant threads/links.
Good luck!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

little problem of file redirection (awk)

I almost reach my objective (Youhouuu !!!!) But I really don't understand why it doesn't work until the end... :wall: For clarity's sake I am taking a very simple example. The operations I am doing in the script (gsub and print) really don't have any importance !!! I just matter about... (10 Replies)
Discussion started by: beca123456
10 Replies

2. Shell Programming and Scripting

Problem with the awk in searching the contents in a file

Hello all, I am a newbie in awk. I am struggling in this problem for a long.Actually I have two files, filea and fileb. File a is actually a search key through it I have to find the corresponding japanese tag from file b. filea contains the data like this: sm982882 sm1893548 sm2420025... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Shell Programming and Scripting

Problem with running awk script in pbs file

Hi guys I have a problem with one module of my script. It's awk script running in pbs file - It's working when I make a call from pbs to separate awk only file like this but when I try to execute this code in pbs file it fails awk 'BEGIN { max = -1000; min = 1000 } { {$4 == "TCO"} ... (2 Replies)
Discussion started by: grincz
2 Replies

4. Shell Programming and Scripting

Awk print to file problem

Hello, I have a file seperated with "|" I want to search the 11th field if it matches certain words change it to an empty space. I have managed to do that, but now I need it to replace the file. this is my code: awk 'BEGIN{OFS=FS="|"}$11=="to... (9 Replies)
Discussion started by: TasosARISFC
9 Replies

5. Shell Programming and Scripting

Problem creating file with awk

Hello, I don't understand why the script below doesn't act the way it should : #!/bin/sh awk 'BEGIN{printf("Entrez la date : "); getline date < "-"} $0 ~ date {f=1;print;next} /^{2}\//{f=0} f' Planning.csv > planning.txt It doesn't create file planning.txt with only the result of... (14 Replies)
Discussion started by: freyr
14 Replies

6. Shell Programming and Scripting

Problem in splitiing file based on regex using awk/nawk

I have a file tmp.txt as shown below: Controller: 0 Disk: 0.0.0 Disk: 0.1.0 Disk: 0.2.0 Controller: 1 Volume:c1t2d0 Disk: 0.0.0 Disk: 0.1.0 Disk: 0.2.0 Controller: 2 Volume:c2t2d0 Disk: 0.2.0 Now I want to split... (4 Replies)
Discussion started by: durbam2002
4 Replies

7. Shell Programming and Scripting

problem with awk for file split

Hi all, i have a .ksh script which is, among other stuff, splitting a file and saveing the filenames into variables for further processing: # file split before ftp and put result filenames into variables if ]; then awk '{close(f);f=$1}{sub("^","");print > f".TXT"}' $_ftpfile set B*.TXT... (0 Replies)
Discussion started by: spidermike
0 Replies

8. Shell Programming and Scripting

awk Problem while insert null field to file

Dear All, I have the following input file. I want to replace data with null values. I/P File: 9022334455|2008-12-06 06:10:21|2|Error@@@|esoo8erp| 9024334432|2008-12-06 08:40:59|6|Error@@@|6y2o8e6r| O/P File: 9022334455||2||esoo8erp| 9024334432||6||6y2o8e6r| ... (4 Replies)
Discussion started by: hanu_oracle
4 Replies

9. Shell Programming and Scripting

problem while searching in a file by 'AWK'

Hi , i am writing a script in which i am using following command to grep some string and then storing it's output to v, as like below :- v=$(awk -F, '{ if ( $NF ~ /DEV/ ) print $0 "_BLD01";else print $0 "_RC01" }' mytest) Here i am facing following issues:- 1. it is searcing DEV in the... (1 Reply)
Discussion started by: inderpunj
1 Replies

10. Shell Programming and Scripting

problem in greping the string from file using awk

I am using awk command for greping an value from the file the file contains .. file ---------------------------- content----------- -------- String main = "81507066666"; ------------------------------ i am greping the above value using awk command NumberToReplace=`cat "file" | grep... (1 Reply)
Discussion started by: vastare
1 Replies
Login or Register to Ask a Question