How to redirect in comma separated csv from grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to redirect in comma separated csv from grep
# 8  
Old 08-25-2012
Quote:
Originally Posted by RudiC
use tr ' ' ',' at the end of the pipe.
Not a good piece of advice. The 5th column might also have spaces. Also, the counts will mostly be preceded by spaces.
This User Gave Thanks to elixir_sinari For This Post:
# 9  
Old 08-25-2012
Actually you know what once I create this file from Linux then using Java I am reading that created excel/csv file and it is failing there.
Exception is "Unable to read entire header". And what I have seen the csv file created through linux is proper. But if I try to create a excel file the values are not appearing in different column , in this case I do not even need ',' as a delimiter.

So can someone tell me how do I create excel file from that grep command so that output goes into different column per row instead of one column per row?
# 10  
Old 08-25-2012
Quote:
Originally Posted by kmajumder
So can someone tell me how do I create excel file from that grep command so that output goes into different column per row instead of one column per row?
Just a suspicion: when you transfer the file from Unix/Linux to Windows to pick it up with Excel, do you adjust the line endings? If not, then Excel probably might be confused ...

Check it with notepad: after transferring the file open it with notepad and if it looks like a regular text file, everything is OK. If everything appears to be on one very long line with funny characters instead of the line feeds then retransmit the file using "ascii" as the FTP mode instead of "binary".

I hope this helps.

bakunin
# 11  
Old 08-25-2012
Hi bakunin,

Thank you for the reply. But I do not think there is any encoding issue. Everything looks great.
The issue is the values are appearing in one column(with , delimited) instead of different column (with no comma).

Desired Excel Output:-

Column1 Column2
Count Field

222 Field5
10 Field5


Thanks,
Kousik
# 12  
Old 08-25-2012
When importing to EXCEL, you can select which chars be the separators. Are you sure you are using "," there?
# 13  
Old 08-25-2012
Yes. I am.
And also other excel files are looking fine except those I create from linux by those grep commands.
# 14  
Old 08-25-2012
Could you please provide meaningful samples of the output of the various stages of your pipeline? Seems like there is something rotten in the state of Denmark.

This was your initial pipe:

Code:
grep -e cmd -e cmd1 test.txt | cut -f 5 | sort | uniq -c> op.csv

Now do the following:

Code:
grep -e cmd -e cmd1 test.txt > intermediate1.out
grep -e cmd -e cmd1 test.txt | cut -f 5 > intermediate2.out
grep -e cmd -e cmd1 test.txt | cut -f 5 | sort > intermediate3.out
grep -e cmd -e cmd1 test.txt | cut -f 5 | sort | uniq -c > op.csv

and post a meaningful part of each of these files, ideally from each the part which deals with the same data.

It might help in finding a solution to see what happens to the data in the various steps. Somehow i believe it might not be what you expect it to be.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

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

3. Shell Programming and Scripting

Need comma separated output

Hi, I am having the file with server names & its corresponding process, i need your help how to convert into comma separated output between server & app #cat apps.txt Server1 oracle was Server2 http webadmin Server3 tsm db2 My requirement is like below. Server1,oracle/was... (5 Replies)
Discussion started by: ksgnathan
5 Replies

4. Shell Programming and Scripting

Needs help in parsing comma separated values

hello experts, i am retrieving values in variables jobKey and jobName within my shell script. these values are returned to me within braces and i am using following command to remove those braces: jobKeys=`echo $jobKeys | sed 's:^.\(.*\).$:\1:'` jobNames=`echo $jobNames | sed... (1 Reply)
Discussion started by: avikaljain
1 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

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

7. Shell Programming and Scripting

Comma separated file

Hi all, I have the following files types: FileA: 100, 23, 33, FileB: 22, 45, 78, and i want to make File C: 100,22 23,45 33,78 any nice suggestions for making it easy. (3 Replies)
Discussion started by: hen1610
3 Replies

8. Shell Programming and Scripting

Need comma separated processing

I have a file like this OUTLN OPEN Y SCOTT OPEN N USER4 OPEN Y DBSNMP EXPIRED & LOCKED N ... (4 Replies)
Discussion started by: ilugopal
4 Replies

9. Shell Programming and Scripting

comma separated string manipulation

hi, i have a script where i am accepting a comma separated string from the user, i have to separated those strings on the basis of comma and store it in variables.. below is the script #!/bin/ksh clear echo "Enter the strings seperated by commas :- \c " read strn echo $strn... (2 Replies)
Discussion started by: saharookiedba
2 Replies
Login or Register to Ask a Question