Delete only commas in a string in AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete only commas in a string in AWK
# 1  
Old 07-25-2012
Delete only commas in a string in AWK

How can I delete just commands in a string. I tried
Code:
x = gsub(/,/,"",$1);

# 2  
Old 07-25-2012
That would delete all commas in the first field. If you want to do it to the entire line, use $0.

Regards,
Alister
# 3  
Old 07-25-2012
I want to delete all commas in the first field, but I still see the commas
# 4  
Old 07-25-2012
Post the entire script, sample input data, actual output, and desired output.
# 5  
Old 07-25-2012
Your gsub() function call looks correct to me. You might want to post your programme, and possibly going into more detail about where exactly you are still seeing the commas.

What is the output if you run the simple command below?
Code:
echo "h,e,l,l,o, world" | awk '{gsub( /,/, "", $1 ); print}'

# 6  
Old 07-26-2012
You were right. I was getting the wrong element.
# 7  
Old 08-01-2012
$ echo "h,e,l,l,o, world" |tr -d ','
hello world
i hope it will solve ur problem
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print commas between awk output

When I output fields 1 2 4 5 & 6, I would like to have a comma between them but I am beating my head against the wall to get it to work. Any help is appreciated sed 's/]*,]*/,/g' file1 > file1.$$ && awk -F, 'FNR==NR{f2=$1 $2 $4 $5 $6;next} FNR==1{print $0, "CDP NE Hostname,CDP NE IP,Remote... (6 Replies)
Discussion started by: dis0wned
6 Replies

2. Shell Programming and Scripting

Remove rows containing commas with awk

Hello everyone, I have a dataset that looks something like: 1 3 2 2 3 4,5 4 3:9 5 5,9 6 5:6 I need to remove the rows that contain a comma in the second column and I'm not sure how to go about this. Here is an attempt. awk 'BEGIN {FS=" "} { if ($2!==,) print }'Any help is appreciated. (5 Replies)
Discussion started by: Rabu
5 Replies

3. Shell Programming and Scripting

How to delete the commas in a .CSV file that are enclosed in a string with double quotes?

Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote. Please see the sample file as below: column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Discussion started by: dhruuv369
8 Replies

4. Shell Programming and Scripting

awk delete line if $5 contains string from list

(5 Replies)
Discussion started by: chrisjorg
5 Replies

5. Shell Programming and Scripting

Find number in string and delete it AWK

Hi all, i have some logs on my linux server that looks like this: CDR.2012-04-30:30-04-2012 14:09:36;123456456654;A;Greetings! Your amount is 42.24 dollars (without VAT) until 30/04/2012 11:00. CDR.2012-04-30:30-04-2012 14:09:36;12154878454212;A;Greetings! Your amount is 4203.2 dollars... (2 Replies)
Discussion started by: arrals_vl
2 Replies

6. Shell Programming and Scripting

Get string between quotes separate by commas

I'm a beginner with shell and tried to do this per hours and everytinhg gives different want i do. So I have a lot of file in *.csv ( a.csv, b.csv ...) in each file csv , it has some fields separeted by commas. ----- "joseph";"21","m";"groups";"j.j@gmail.com,j.j2@hotmail.com"... (6 Replies)
Discussion started by: flaviof
6 Replies

7. Shell Programming and Scripting

delete string using AWK

inputfile has 3 columns SCHEMA.TAB1 COL1 LENGTH SCHEMA.TAB2 COL2 LENGTH. If i use awk on the above inputfile awk '{print $1}' inputfile.The out put will be SCHEMA.TAB1 SCHEMA.TAB2. But from the above output i need to delete SCHEMA. i.e i don't want the string "SCHEMA." should... (6 Replies)
Discussion started by: rocking77
6 Replies

8. Shell Programming and Scripting

how to find the count of commas in a string excluding the ones in double quotes

Hi, my requirement is to find the count of commas in a string excluding the ones in double quotes. For example: If the input string is abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45 The output should be 7 (7 Replies)
Discussion started by: amitshete
7 Replies

9. Shell Programming and Scripting

Help with removing additional commas in string

Hi Experts, I have below strings hello,hi,,,,,,start date age,code,,,,,61,season I am trying to format this string to hello,hi,start date age,code,61,season Can anyone please help me in achieving this? Kind Regards, RB (3 Replies)
Discussion started by: ramakanth_burra
3 Replies

10. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies
Login or Register to Ask a Question