Visit Our UNIX and Linux User Community


Save log data in excel sheet


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Save log data in excel sheet
# 1  
Old 08-19-2013
Linux Save log data in excel sheet

Hello,

I have the following data format in a log file :
Code:
a : x1
b : x2
c : x3
d : x4
--------
a : x5
b : x6
c : x7
d : x8

so the same fields ( a ,b ,c,d) repeated many times in the same log file but with different "x" values (x5,x6,x7,x8).

I need a script to save this data in an excel sheet in the following format:
Code:
a        b      c      d
x1       x2     x3    x4
x5       x6     x7    x8

Thanks in advance....

Last edited by Franklin52; 08-20-2013 at 04:18 AM.. Reason: Please use code tags
# 2  
Old 08-19-2013
Excel can understand CSV files natively, so all you need is this:

Code:
awk -F":" '{ A[$1]=A[$1]","$2 } END { for(X in A) print X A[X] "\r" }' inputfile > output.csv

# 3  
Old 08-19-2013
Try also:
Code:
awk     '/------/       {next}
                        {hd[$1]++
                         ln[hd[$1],$1]=$3}
         END            {for (i in hd) printf "%s,", i; printf "\n"
                         while (n++ < hd[$1]) {for (i in hd) printf "%s,", ln[n,i]; printf "\n"}
                        }
        ' file
a,b,c,d,
x1,x2,x3,x4,
x5,x6,x7,x8,

# 4  
Old 08-20-2013
Many thanks for your replies
the problem with these scripts is that if x value is more than one word the script will not display the full line.so if for example x1 is "hello word" the above scripts will display "hello" only.
# 5  
Old 08-20-2013
Code:
awk   -F :  '/------/       {next}
                        {hd[$1]++
                         gsub(/^ */,"",$2);ln[hd[$1],$1]=$2}
         END            {for (i in hd) printf "%s,", i; printf "\n"
                         while (n++ < hd[$1]) {for (i in hd) printf "%s,", ln[n,i]; printf "\n"}
                        }
        ' infile

# 6  
Old 08-20-2013
Another awk
Code:
awk 'NR%5 {printf "%s ",$3;next}1'

# 7  
Old 08-20-2013
@Jotne: this works if there's always 4 data lines. My approach tries to allow for more data lines. I'm sure, though, that it deserves quite some polishing, still.
@rdcwayx: thanks for adapting to the requestors NEW specification!

Previous Thread | Next Thread
Test Your Knowledge in Computers #246
Difficulty: Easy
By 1973, e-mail constituted 95% of the ARPANET traffic.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Summing up the data from different excel sheet into one excel sheet

Hi Folks, Can you please advise for any script in unix such that for example , i have 3 different excel sheet at the location /ppt/gfr/exc so the name s of the excel sheet are 1excel.xslx 2excel.xslx 3excel.xslx now in these 3 different excel sheet there is lot of data for example each... (3 Replies)
Discussion started by: punpun66
3 Replies

2. UNIX for Dummies Questions & Answers

UNIX data to be updated to ms excel sheet

hi, i wanted to add unix data to be updated to the excel sheet. (3 Replies)
Discussion started by: rupesh.bombale
3 Replies

3. UNIX for Dummies Questions & Answers

Load UNIX data into excel sheet

Hi, i have some data in a temporary file in Unix (the data is taken from the result of an SQL query). Now i want to dump that data into an excel sheet. How to do that. Someone please advise. Thanks Regards, Vinit (3 Replies)
Discussion started by: vinit raj
3 Replies

4. Shell Programming and Scripting

Copy Data from CSV file to Excel Sheet using Perl

Hi All, Firstly I will like to wish A Happy New Year to all. Now my issue is I have one csv file say(data.csv) and one excel file say(result.xls) The result.xls contains two sheet name Sheet1 and Sheet2, Now What I am trying to do is to First I want to delete that data of Sheet2 if present any,... (6 Replies)
Discussion started by: adisky123
6 Replies

5. Programming

converting data from excel sheet to oracle using toad

guys i have data in excel sheet , how do i convert that data to database table (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

6. Shell Programming and Scripting

Perl : not capturing all the data from excel sheet

Hi folks, I am working on assignment that captures all the records(2 columns one column contains names and other contain date of birth) from excel sheet stored in a directory and checks for current date and month. If it matches current date and month then the matched records are printed as... (1 Reply)
Discussion started by: giridhar276
1 Replies

7. Shell Programming and Scripting

HOWTO create in UNIX a Microsoft Excel-Sheet (with data from Oracle)

Hi HOWTO create in UNIX a Microsoft Excel sheet (with data from Oracle). At the moment I am making CSV files (using SQL statemens with || ';'), but search for more advanced formatting. Don't wish to use Perl. cheers (4 Replies)
Discussion started by: slashdotweenie
4 Replies

8. Shell Programming and Scripting

Filter data in Excel sheet using Shell Script

Hi, I have an excel sheet which has 100000 records. All these records are having 3 columns each with the last column as "Y" or "N". I would like to filter those records which has the value "Y". Can you please let me know how to proceed with that? Thanks in advance. -Sri ----------... (8 Replies)
Discussion started by: bhanusri83
8 Replies

9. Shell Programming and Scripting

How to convert the data into excel sheet and send mail using 'mailx' command

Hi all I have a shell script that uses a stored proc to generate output from some tables and send the same in an e-mail using mailx command. Now I need to convert the output to excel format and send e-mail. How can I achieve this. Please help me in this regard, as it's very urgent and I have been... (5 Replies)
Discussion started by: sanbabu
5 Replies

10. UNIX for Advanced & Expert Users

how to read the data from an excel sheet and use those data as variable in the unix c

I have 3 columns in an excel sheet. c1 c2 c3 EIP_ACCOUNT SMALL_TS_01 select A.* from acc; All the above 3 col shoud be passed a variable in the unix code. 1.How to read an excel file 2.How to pass these data as variable to the unic script (1 Reply)
Discussion started by: Anne Grace
1 Replies

Featured Tech Videos