Comma separate issue in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Comma separate issue in UNIX
# 1  
Old 09-18-2014
Comma separate issue in UNIX

In awk the field seprator is not working properly, I am trying to cut the fields from the file based on the delimiter example comma (,)

Code:
awk -F, "{print {$1 FS $3 FS $5 FS FS $2}}" Sample.csv

But i am not getting desired output can anyone help me how to check real ascii comma there in my sample.csv file if not what to do ?
# 2  
Old 09-18-2014
Could you give us a bit of your sample.csv so we can see...
What OS and shell are you using?
# 3  
Old 09-18-2014
Posted by rspwilliam:
Quote:
In awk the field seprator is not working properly, I am trying to cut the fields from the file based on the delimiter example comma (,)



Code:
awk -F, "{print {$1 FS $3 FS $5 FS FS $2}}" Sample.csv

But i am not getting desired output can anyone help me how to check real ascii comma there in my sample.csv file if not what to do ?
Hello rspwilliam,

You can use ' character in place of " and try as follows.
Code:
awk -F, '{print {$1 FS $3 FS $5 FS FS $2}}' Sample.csv

Thanks,
R. Singh
# 4  
Old 09-18-2014
Awk code and sample data

Code:
fields=$(sed -r -e 's/-1/ /g' -e 's/,/ FS /g' \
  -e 's/([0-9]+)/\$\1/g' control_file.txt)

The first command converts control_file.txt into a suitable awk command like below,
control file contain the index need to be cut from the sample.csv

$1 FS $3 FS $5 FS FS $8 FS FS $4

Then passing to awk
Code:
awk -F, "{print ${fields}}" $1

Sample.csv
Code:
BP ID,Prepaid Account No,CurrentMonetary balance ,charge Plan names ,Provider contract id,Contract Item ID,Start Date,End Date
1100001538,001000002506,251,[B2] R2 LTE CHARGE PLAN ,00000000000000000141,[B2] R2 LTE CHARGE PLAN _00155D10E20D1ED39A8E146EA7169A2E00155D10E20D1ED398FD63624498DB4A,16-Oct-12,18-O*​ct-12 
1100003404,001000004029,45.22,B0.3 ECS_CHARGE_PLAN DROP1 V3,00000000000000009349,B0.3 ECS DROP2 V0.2_00155D10E20D1ED39A8E146EA7169A2E00155D10E20D1ED398FD63624498DA2E,16-Nov-13,*​23-Nov-13

---------- Post updated at 08:10 AM ---------- Previous update was at 08:02 AM ----------

Quote:
Originally Posted by RavinderSingh13
Posted by rspwilliam:

Hi Singh,

it's telling syntax error

William R

Hello rspwilliam,

You can use ' character in place of " and try as follows.
Code:
awk -F, '{print {$1 FS $3 FS $5 FS FS $2}}' Sample.csv

Thanks,
R. Singh
# 5  
Old 09-18-2014
Hello rspwilliam,

Kindly try the following it should help.

Code:
awk -F, '{print $1 FS $3 FS $5 FS FS $2}'  Input_file

Thanks,
R. Singh
# 6  
Old 09-18-2014
Code:
n12:/home/vbe/wks/test/awk $ awk -F, '{print $1 FS $3 FS $5 FS FS $2}' 0008.sample
BP ID,CurrentMonetary balance ,Provider contract id,,Prepaid Account No
1100001538,251,00000000000000000141,,001000002506
1100003404,45.22,00000000000000009349,,001000004029

??? Seems to work...
# 7  
Old 09-18-2014
Quote:
Originally Posted by RavinderSingh13
Hello rspwilliam,

Kindly try the following it should help.

Code:
awk -F, '{print $1 FS $3 FS $5 FS FS $2}'  Input_file

Thanks,
R. Singh
Hi Singh,

The code should work but in for my csv its not working , But when i create sample dummy file its work perfect , some ASCII issue required help on that
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

2. Windows & DOS: Issues & Discussions

Parsing a UNIX txt to separate files

I have a requirement to parse a dataflex .txt file and break it into separate files within the Windows server env. Is there any special characters I should pay particular attention on the unix side? Any ideas? Thanks in advance (2 Replies)
Discussion started by: kicklinr
2 Replies

3. Shell Programming and Scripting

Separate Entries after comma

Hi All I need help to separate entries after commas in my I have 2 columns in my file like this Ramush, Shyam, Mohan First Ram, Mohan, Kaavya Second, Fourth Kavi, Ram, Shaym, Mohan Third I ahve to separate entries after comma in a separate row... (9 Replies)
Discussion started by: kareena
9 Replies

4. Shell Programming and Scripting

Remove bracket part entires and separate entries after comma

Hi all This time my input conatin 3 columns: ERCC1 (PA155) Platinum compounds (PA164713176) Allele A is not associated with response to Platinum compounds in women with Ovarian Neoplasms as compared to allele C . CES1 (PA107) methylphenidate (PA450464) Genotype CT is not... (4 Replies)
Discussion started by: Priyanka Chopra
4 Replies

5. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

6. Shell Programming and Scripting

Extract comma separated value in unix

Hello All Can anyone please guide me how to solve the issue In the below code I am getting concat of two value in result variable with comma separated result=`sqlplus -s / <<EOF set pages 0 feed off; set feedback off; spool abc.txt select... (4 Replies)
Discussion started by: Pratik4891
4 Replies

7. Shell Programming and Scripting

using diff to on two file but ignoring the last comma separate value

Hi guys I have two file which I sdiff. ie file 1: AA,12,34,56,,789,101,,6666 file 2: AA,12,34,56,,789,101,,7777 The last comma separated value will always change from one day to the next. Is there another unix utility I can use that will sdiff two files but ignore the last comma... (1 Reply)
Discussion started by: wny201
1 Replies

8. UNIX for Advanced & Expert Users

Replacing the comma in .csv file in unix

Hi All, Could some one help me on one of my requirement below: I have a sequential file with 4fields in it and it is a comma (,) seperated file. Delimeter is 'comma'. But in of the file column for ex: 3rd column it is 'Description' (column name) I am getting the values with commas.... (6 Replies)
Discussion started by: eskay_s
6 Replies

9. UNIX Desktop Questions & Answers

Unix Comma Separated to Excel Column

I would like to copy 2 parts of a csv file from Unix to an XL sheet. However to save time I do not want to format the column ever time I cut and paste into XL(Text2Column). I've used awk -F, '{Print $1, $2....}'. Is there a script or code that can automatically format the csv for XL columns? ... (3 Replies)
Discussion started by: ravzter
3 Replies

10. Shell Programming and Scripting

count data separate by comma

hi experts, i have some problem with count data which separate by comma, below sample data : 01,011222823b6d,011222823f29,0028a5,002993,6212345678, 659111111111,6598204507,6281105008,6596197849,_,525016160836958,_, ffffffff,000000000000000000000000,_,_,_,fd,fd,ff,00,1,0028a5-002993,_,... (10 Replies)
Discussion started by: bucci
10 Replies
Login or Register to Ask a Question