convert this into csv using awk/shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert this into csv using awk/shell script
# 1  
Old 12-16-2008
convert this into csv using awk/shell script

Hi Scripting gurus,

I need to convert following text snippet into csv. please help

Input

heading1 = data1
heading2 = data2
..
..
heading n = data n

heading 1 = data1
..
..


Output

data1,data2,....,data n
data1,data2,....data n

Even a small help like how to go ahead is appreciated.

Thanks
Ajay
# 2  
Old 12-16-2008
You can use awk for this issue.

awk -F'=' '{ print $2}' .make sure that you use escape sequence so ,data2,date3 will print on the same line..

use loop each time to check if heading 1 is repeated or not ..if repeated print newline...
# 3  
Old 12-16-2008
Code:
perl -ne'print/=\s*(.*)/,(eof)?$/:","' infile

# 4  
Old 12-16-2008
Code:
$num=<>;
undef $/;
open FH,"<file";
$str=<FH>;
@arr=split("\n",$str);
for($i=0;$i<=$#arr;$i++){
	if (((1+$i) % $num) == 0){print $arr[$i]."\n";}
	else {print $arr[$i].",";}
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to convert IP range csv into a list of single IP's

Hi All, I am looking for some help to convert a csv with IP ranges in.. in the format e.g. 1.1.1.2, 1.1.1.5 2.1.1.10, 2.1.1.20 and would be looking to output as follows: 1.1.1.2 1.1.1.3 1.1.1.4 1.1.1.5 2.1.1.10 2.1.1.11 etc etc up to 2.1.1.20 I have tried a few google... (4 Replies)
Discussion started by: zippyzip
4 Replies

2. Shell Programming and Scripting

Need script to convert TXT file into CSV

Hi Team, i have some script which give output in TXT format , need script to convert TXT file into CSV. Output.TXT 413. U-UU-LVDT-NOD-6002 macro_outcome_dist-8.0.0(v1_0_2) KK:1.2.494 (1234:333:aaa:2333:3:2:333:a) 414. U-UU-LVDT-NOD-6004 ... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies

3. Shell Programming and Scripting

Convert XML to CSV using awk or shell script

Hello, I am working on a part of code where I need a awk or shell script to convert the given XML file to CSV or TXT file. There are multiple xml files and of different structure, so a single script is required for converting data. I did find a lot of solutions in the forum but... (16 Replies)
Discussion started by: Rashmitha
16 Replies

4. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

5. Shell Programming and Scripting

Script to convert CSV file to HTML

Hi, I have made a a script which creates a csv file as daily database report However i want to covert that csv file to html because csv file does not have a good visibilty. So it is possible to have such csv to html coversion script. Your prompt help much appreciated. Thanks in advance (4 Replies)
Discussion started by: sv0081493
4 Replies

6. Shell Programming and Scripting

awk convert xml to csv

Hi, I have an xml file and I want to convert it with awk in to a csv file Test.xml <Worksheet ss:Name="Map1"> <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60"> <Row> <Cell><Data... (6 Replies)
Discussion started by: research3
6 Replies

7. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

8. Shell Programming and Scripting

Awk script to convert csv to html

Hi Written some script to convert csv to html but could not add table headers.Below are the errors iam getting ./csv2html | more + awk -v border=1 -v width=10 -v bgcolor=black -v fgcolor=white BEGIN { printf("<table border=\"%d\" bordercolor=\"%s\" width=\"%d\"... (2 Replies)
Discussion started by: zeebala1981
2 Replies

9. Shell Programming and Scripting

script to convert CSV to SQL

I am trying to write a script to convert csv files into SQL format. What I am missing is: 1. handling of the first row and create it as a insert into format 2. better handling of any other row, and create a line with the data. *The while read line needs a better work. I thought of using awk. ... (1 Reply)
Discussion started by: saariko
1 Replies

10. Shell Programming and Scripting

Shell convert xls to csv

Hi does anybody know how to convert xls to csv undex linux. I need only data (that is log from test, dont need any macro and so on) from xls. Any idea how to do that? Perl? shell? Could you give me any example? Thanks in advance for answer. Gracjan (4 Replies)
Discussion started by: Gracjan
4 Replies
Login or Register to Ask a Question