Comma separate issue in UNIX


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Comma separate issue in UNIX
# 8  
Old 09-18-2014
So its more to do with the content of you csv file...
Have you tried to extract I dont know 20 first lines? and see if you already have issues?
Where does de csv file come from?
# 9  
Old 09-18-2014
Posted by rspwilliam:
Quote:
Quote:
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
Hello rspwilliam,
Could you please make sure that file is not having Windows carriage return charcters etc. you can use tr -d "\r" command if there are those characters present in your input file and then use the awk command to get the expected output.

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-18-2014 at 10:40 AM..
# 10  
Old 10-06-2014
Quote:
Originally Posted by rspwilliam
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]
---
If you need to pass values from shell to awk variables, this is absolutely not the right method. You should instead pass values to an awk script this way:
awk -F, -vFields="$fields" '{ print Fields...}
By the way you can shorten awk script by specifying the OutPut Field Separator to ",". So this will give finally:
awk -F, -vFields="$fields" -vOFS="," '{print Fields, "sample", ...}' files...

Last edited by blastit.fr; 10-06-2014 at 04:36 PM.. Reason: typoes
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