Shell scripting:from text file to CSV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting:from text file to CSV
# 8  
Old 06-18-2013
Many thanks RudiC,

and for a normal file like this:

Code:
content1
content2
content1
content2
content1
content2
content1
content2


thanks
# 9  
Old 06-19-2013
Code:
paste -s -d",,\n" file
content1,content2,content3
content1,content2,content3 
content1,content2,content3

This User Gave Thanks to RudiC For This Post:
# 10  
Old 06-19-2013
hello rudiC,

somthing like this doesn't works

Code:
awk -F -s -d",,\n" 'BEGIN{RS=""; OFS=",";} {print $1,$2}'

?

thnaks
# 11  
Old 06-20-2013
Code:
$ cat file | xargs -n 2 echo | tr " " ","
content1,content2
content1,content2
content1,content2
content1,content2

Code:
$ cat file | xargs -n 3 echo | tr " " ","
content1,content2,content1
content2,content1,content2
content1,content2

This User Gave Thanks to rajamadhavan For This Post:
# 12  
Old 06-20-2013
Another paste approach:
Code:
paste -d, - - < file

Another awk approach:
Code:
awk 'NR%2{ORS=OFS}!(NR%2){ORS=RS}1' OFS=, file

This User Gave Thanks to Yoda For This Post:
# 13  
Old 06-20-2013
Quote:
Originally Posted by kraterions
hello rudiC,
somthing like this doesn't works
Code:
awk -F -s -d",,\n" 'BEGIN{RS=""; OFS=",";} {print $1,$2}'

?
thnaks
No. Try
Code:
awk 'NR%2 {x=$1;next} {print x","$1}' file
content1,content2
content1,content2
content1,content2
content1,content2

And, in my other post, remove one comma from -d",,\n". Sorry, should have read your question more carefully.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

3. Shell Programming and Scripting

Need a piece of shell scripting to remove column from a csv file

Hi, I need to remove first column from a csv file and i can do this by using below command. cut -f1 -d, --complement Mytest.csv I need to implement this in shell scripting, Whenever i am using the above command alone in command line it is working fine. I have 5 files in my directory and... (3 Replies)
Discussion started by: Samah
3 Replies

4. Shell Programming and Scripting

How to calculate avg values of csv file using shell scripting .?

hi all i have a reporting work and i want it to be automated using shell scripting kindly let me know how can i make that possibe . eg data are :... (2 Replies)
Discussion started by: Avinash shaw
2 Replies

5. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

6. Solaris

XML to Text file Parsing Using shell scripting

Hi, I want to parse an XML File using Shell Script preferably by using awk command, I/P file is : <gn:ExternalGsmCell id="016P3A"> <gn:attributes> <gn:mnc>410</gn:mnc> <gn:mcc>310</gn:mcc> <gn:lac>8016</gn:lac> ... (2 Replies)
Discussion started by: tech_frk
2 Replies

7. Shell Programming and Scripting

XML to Text file Parsing Using shell scripting

Hi folks, Need some help with XML to text file parsing , the following is the content of the XML File. <xn:SubNetwork id="SNJNPRZDCR0R03"> <xn:MeContext id="PRSJU0005"> <xn:VsDataContainer id="PRSJU0005"> <xn:attributes> ... (6 Replies)
Discussion started by: tech_frk
6 Replies

8. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

9. Shell Programming and Scripting

exporting number into .csv file in text form (no other extra charc) from shell script

I have written a k shell program which is executing a sql and exporting data in numeric form like 0412323444 into .csv file. the problem i am facing is that , the data is coming in excel formatted in scientific form like 4.1+E08,while my requirement is to store data as such 0412323444 in excel ( no... (5 Replies)
Discussion started by: Deepak_Rastogi
5 Replies

10. UNIX for Dummies Questions & Answers

Shell scripting adding text to top of file

Hi this is quite simple i am sure but without using awk or sed i need to add text to the top of a file this is what i have got so far #!bin/bash echo "Add text to top of file" read line echo $line >> file1 This adds the text to the bottom of the file can some1 please help cheers (7 Replies)
Discussion started by: meadhere
7 Replies
Login or Register to Ask a Question