creating a csv file from this 1 liner?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting creating a csv file from this 1 liner?
# 1  
Old 01-11-2011
creating a csv file from this 1 liner?

I'm trying to create a csv file by running awk and sed on a number of xml files in a directory; I'm using this below:
Code:
hostname; grep "BuildDate" /dir/ABCD/configuration/*/*.xml | awk -F"/" '{ print $5 }' > /tmp/tempfile.txt; grep "BuildDate" /dir/ABCD/configuration/*/*.xml | awk -F\" '{ print $2 }' >> /tmp/tempfile.txt; sed -n 's/.*<Long>\([^<]*\)<\/Long>.*/\1/p' /dir/ABCD/configuration/*/*.xml >> /temp/tempfile.txt

The issue I have is that I can't write and deploy a shell script onto the box I'm running the above commands on (not allowed basically - insane I know) so I'm having to run the whole of the above as a 1 liner in the terminal when logging onto the box by seperating commands with ';'. This is returning the info I want in the following format:

Code:
hostname
SERVER_1
SERVER_2
SERVER_3
1.5.019.01
1.5.019.02
1.5.016.03
This is a description of server1
This is a description of server2
This is a description of server3

but I need to generate a csv file in the following format:

Code:
hostname,SERVER_1,1.5.019.01,This is a description of server1
hostname,SERVER_2,1.5.019.01,This is a description of server2
hostname,SERVER_3,1.5.016.03,This is a description of server3

is there a way to get the above format by extending the what I have already?
# 2  
Old 01-11-2011
Well... you've left your intermediate output pretty typeless... so it's NOT hard to write an awk or something to parse your intermediate output and take it to CSV, BUT, you have to assume that the number of SERVER_* entries is always 3. My guess is that there might be some type data that can pass through.... possible to see the actual data sources? Just trying to help this to handle a variable number of data instead of just 3.
# 3  
Old 01-12-2011
If you show us a reasonable example of your XML files, I can probably provide you a simple XSLT stylesheet that will generate a CSV file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Creating a csv file with header in UNIX

I have a flat file that contains dynamic list of variables like a=1 b=2 c=3 . .. z=26 I need to convert the above into a csv file having the format below: a,b,c,..,z 1,2,3,..,26 Please note, I do not want a comma separating the last variable. I tried to refer the post... (4 Replies)
Discussion started by: vkumbhakarna
4 Replies

2. UNIX for Dummies Questions & Answers

Problem in creating CSV file

Hi guys, I am not experienced with Unix, so please dont mind if the question seem to be irrelevant. I have written a simple script, that connects DB & fetches few records from a table. I wanted to get those details as file in .CSV format via mail. -I stored the query o/p in a file. -I... (6 Replies)
Discussion started by: sumitburnwal88
6 Replies

3. UNIX for Dummies Questions & Answers

Creating a report from csv file.

Hi Gurus, I need your help in transforming the CSV file into some what a report format. My source file looks like below Date,ProdID,TimeID,LevelID 2010-08-31,200,M,1 2010-08-31,201,Q,2 2010-08-31,202,Y,1 2010-08-31,203,M,5 Output required is ... (9 Replies)
Discussion started by: naveen.kuppili
9 Replies

4. UNIX for Dummies Questions & Answers

Creating a one liner with wget, grep and mv

I have the following simplified script, that consists of a download (wget), a grab of only the lines with a comma (grep) and a rename of the file to indicate its date of origin (mv): wget http://www.example.com/datafile.csv grep ',' datafile.csv mv datafile.csv datafile.`date... (2 Replies)
Discussion started by: figaro
2 Replies

5. Shell Programming and Scripting

csv to table one-liner

I've googled a lot on this, but could not fine a simple one-liner to do this. I have a .csv file that looks like this: Header one Header two Header three col1,col2,col3 short data, very long data, dataIf I use sed and change the comma to tab, being the colums of variable length I don't get a... (6 Replies)
Discussion started by: ahsog
6 Replies

6. UNIX for Dummies Questions & Answers

creating a CSV file for past 7 days

I have a requirement which will select the files with a specific naming convention which got created in past 7 days in a specific directory.Lets say the directory is /data/XYZ and the file names follow the below nomenclature like Daily_File*.txt I just need to create one CSV file which will... (12 Replies)
Discussion started by: dr46014
12 Replies

7. UNIX for Advanced & Expert Users

Creating multiple worksheets in CSV file

Hello, I've been tasked with sending 3 types of data (file size, row count, and file name) to a csv file every month for various vendors. I have been asked to put this in one csv or xls file with each vendor being a different tab (or worksheet). Until now, we have been finding and emailing... (4 Replies)
Discussion started by: tekster757
4 Replies

8. Shell Programming and Scripting

creating a csv file in awk

Hi All I am trying to create a csv file in the korn shell and the script segment is as follows: if then # NEED TO ADD INFO TO THE EMAIL FILE ABOUT THE DRIVE THAT'S FILLING UP echo "$drive $percent% $space "|\ awk '{printf("%d/t"|"%d/t"|"%d/t\n",... (6 Replies)
Discussion started by: Segwar
6 Replies

9. Shell Programming and Scripting

Creating a csv file based on Existing file

Hi I am Newbie to Unix.Appreciate Help from forum user would loada b.Csv File(Below example) in /data/m/ directory.Program need to read the b.csc to extract certain column and create a new file /data/d/ directory as csv file with new name. User File Format 1232,samshouston,12345... (3 Replies)
Discussion started by: skywayterrace
3 Replies

10. Shell Programming and Scripting

merging CSV data using a one liner from shell?

I'm trying to merge multiple CSV (comma separated value) files into one large master file. All files have a field that is unique to act as the key for entry/merging into the master file & and all files have the same number of fields that are in the master file. I'll give an example here: ... (2 Replies)
Discussion started by: jjinca
2 Replies
Login or Register to Ask a Question