Trying to combine 2 lines into one CSV format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to combine 2 lines into one CSV format
# 1  
Old 02-25-2012
Trying to combine 2 lines into one CSV format

Hi,

I have the following test script I'm working with:

Code:
date +"%m-%d-%y">>test.log
grep eth0 /proc/net/dev | awk '{print ",",$2/1024/1024,",",$10/1024/1024}'>>test.log

The output looks like this:

02-25-12
, 19.3581 , 84.2826
02-25-12
, 19.3587 , 84.283
02-25-12
, 19.3587 , 84.283
02-25-12
, 19.3596 , 84.2838
02-25-12
, 19.3596 , 84.2838

I would like to make the output look like this:

02-25-12 , 19.3581 , 84.2826
02-25-12 , 19.3587 , 84.283
02-25-12 , 19.3587 , 84.283
02-25-12 , 19.3596 , 84.2838
02-25-12 , 19.3596 , 84.2838

Help?
# 2  
Old 02-25-2012
Try:
Code:
echo `date +"%m-%d-%y"``grep eth0 /proc/net/dev | awk '{print ",",$2/1024/1024,",",$10/1024/1024}'`>>test.log

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 02-25-2012
That works awesome! Thanks!

---------- Post updated at 11:28 AM ---------- Previous update was at 11:26 AM ----------

@ bartus11

The output is now:
02-25-12 , 19.3596 , 84.2838

Any idea how to eliminate the extra spaces? No big deal if we can't. Excel should import the CSV ok now.
# 4  
Old 02-25-2012
Code:
echo `date +"%m-%d-%y"``grep eth0 /proc/net/dev | awk '{print ","$2/1024/1024","$10/1024/1024}'`>>test.log

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 02-25-2012
Thanks again!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine and complete multiple CSV files based on 1 parameter

I have to create a new CSV file based on the value listed on the 3rd column from different CSV files. This is what I need: 1. I should substitute the first column from each file, excluding the headers, with the file name InputXX. 2. Then, I need to look for rows with 0 on the third column in... (7 Replies)
Discussion started by: Xterra
7 Replies

2. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies

4. Shell Programming and Scripting

Combine multiline to one line with proper format

Hello Guys, I have a file say FILE1.txt contains below data:- A B C D E F G H I J K L I need the output in another file as FILE2 as:- 'A', 'B', 'C', 'D', 'E', (7 Replies)
Discussion started by: jassi10781
7 Replies

5. Shell Programming and Scripting

Need perl or shell script to sort vertical lines to horizontal line in csv format

Need perl or shell script to sort vertical lines to horizontal line in csv format My file like below ------------------------- ================================================================================ PATH PINKY1000#I1-1-ZENTA1000-2#I7-1-ASON-SBR-UP-943113845 ... (4 Replies)
Discussion started by: sreedhargouda.h
4 Replies

6. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

7. Shell Programming and Scripting

Combine two files and put it in .csv file

Hi Freinds I have two .txt file gem1.txt and gem2.txt, Sample gem1.txt abstract (1.0.0) actionmailer (2.3.5, 2.2.2) actionpack (2.3.5, 2.2.2) activerecord (2.3.5, 2.2.2) activerecord-oracle_enhanced-adapter (1.1.9) activerecord-sqlserver-adapter (2.3.4) activeresource (2.3.5, 2.2.2)... (3 Replies)
Discussion started by: ankit_view24
3 Replies

8. Shell Programming and Scripting

Combine Multiple text or csv files column-wise

Hi All I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below. What can i do to resolve this ? File 1 File... (15 Replies)
Discussion started by: venky_ibm
15 Replies

9. Shell Programming and Scripting

Combine csv's

All, I would like to combine two csv's. File1 text,text,value1 text,text,value1 text,text,value1 file2 text,text,value2 text,text,value2 text,text,value2 Note: Text fields will be the same in each file so can be taken from either (4 Replies)
Discussion started by: pxy2d1
4 Replies

10. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies
Login or Register to Ask a Question