how to handle , in data where separator also commas in awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to handle , in data where separator also commas in awk script
# 1  
Old 03-30-2010
how to handle , in data where separator also commas in awk script

Code:
TEST_HEME,"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1",CELL

when I split by

Code:
FS=","

then

Code:
$0=TEST_HEME
$1="SubNetwork=ONRM_RootMoR
$2=SubNetwork=ARNC1"

but I need this will be single value

Code:
"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1"


Last edited by radoulov; 03-30-2010 at 06:49 AM.. Reason: Please use code tags!
# 2  
Old 03-30-2010
In this case I would use Perl instead of awk:

Code:
% print 'TEST_HEME,"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1",CELL' | 
  perl -MText::ParseWords -nle'
    print for parse_line(",",0, $_);
  '
TEST_HEME
SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1
CELL

# 3  
Old 03-30-2010
Thanks for the reply.
but I have to do it in awk script .
and i have only FS to set

FS=","
TEST_HEME,"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1",CELL

TEST_HEME,"SubNetwork=ONRM_RootMoR , SubNetwork=ARNC1",CELL

I need to set value of FS which split only string which out of " " if it is in " " so it should ignore
# 4  
Old 03-30-2010
Quote:
Originally Posted by Hemendra
Thanks for the reply.
but I have to do it in awk script .
and i have only FS to set

FS=","
Why? What's wrong with Perl?

Quote:
TEST_HEME,"SubNetwork=ONRM_RootMoR,SubNetwork=ARNC1",CELL

TEST_HEME,"SubNetwork=ONRM_RootMoR , SubNetwork=ARNC1",CELL

I need to set value of FS which split only string which out of " " if it is in " " so it should ignore
awk is not the right tool for parsing such a CSV data ...
# 5  
Old 03-30-2010
Take a look here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a way to handle commas inside the data when generating a csv file from shell script?

I am extracting data via sql query and some of the data has commas. Output File must be csv and I cannot update the data in the db (as it is used by other application). Example table FavoriteThings Person VARCHAR2(25), Favorite VARCHAR2(100) Sample Data Greta rain drop on... (12 Replies)
Discussion started by: patk625
12 Replies

2. Shell Programming and Scripting

How to handle grepping variable data containing wildcards?

I have a lot of files with keywords and unique names. I'm using a shell script to refer to a simple pattern file with comma separated values in order to match on certain keywords. The problem is that I don't understand how to handle the wildcard values when I want to skip over the unique names. ... (5 Replies)
Discussion started by: abercrom
5 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Delete only commas in a string in AWK

How can I delete just commands in a string. I tried x = gsub(/,/,"",$1); (7 Replies)
Discussion started by: codecaine
7 Replies

5. Shell Programming and Scripting

problem in using cgi_script to handle form data

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (0 Replies)
Discussion started by: piyush_priya
0 Replies

6. Shell Programming and Scripting

replace but skip data between certain commas

OK, I am one needy dude. However, how can I make the program NOT change any of the values BETWEEN the first and second "," ? I dont want any of the numbers changed that are preceded by "AT". I want ALL other numeric values > 300 changed to 300. cat qin.csv |head... (4 Replies)
Discussion started by: herot
4 Replies

7. Web Development

Data type to use for prices with commas

Hi everybody, I`m very new with PHP and Databases and I having the follow issue with prices data.. The original information is in CSV files. The prices have formatted with commas and dots as follow: 12,300.99 -->(thousands separated by commas) 3,500.25 -->(thousands separated... (10 Replies)
Discussion started by: cgkmal
10 Replies

8. 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

9. Shell Programming and Scripting

Separator in data itself

Following is the CSV file, separated by "," 100,sunil,$1,000,mumbai 101,amit,$10,000,mumbai 102,sailesh,$10,000,00,mumbai I want the following output: 100,sunil,$1000,mumbai 101,amit,$10000,mumbai 102,sailesh,$1000000,mumbai Note: I know the number of fields in the file in advance. In... (2 Replies)
Discussion started by: kolesunil
2 Replies

10. Shell Programming and Scripting

Piped open not real-time - How would one handle live data?

When I run "/etc/myApp" I am presented with continuous output, just about once per second. However when I try to get the information in Perl via a piped open, it waits till the end to give me anything... my code: open (OUTPUT,"/etc/myApp |"); while (<OUTPUT>){ print $_; }... (2 Replies)
Discussion started by: jjinno
2 Replies
Login or Register to Ask a Question