Format log data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format log data
# 1  
Old 10-30-2013
Format log data

I have hundreds of lines similar to this:

Code:
Oct 30 10:06:40 localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
Oct 30 10:06:40 localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0

i want to add a comma after the date, and then print the remaining text to the end of the line.

the preferred output should be:
Code:
Oct 30 10:06:40, localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0
Oct 30 10:06:40, localhost kernel: sd 2:0:0:0: Attached scsi generic sg1 type 0

i tried:

Code:
tail -5 datafile | cut -d' ' -f1,2,3,4-

and
Code:
tail -5 datafile | awk '{print $1" "$2" "$3","$NF}'

both of these are incomplete. can someone help me finish it off? i'd prefer the awk solution.

Last edited by SkySmart; 10-30-2013 at 06:05 PM..
# 2  
Old 10-30-2013
Try this :
Code:
awk '{$3=$3","}1' input_file

This User Gave Thanks to greet_sed For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Log file data into CSV format

I m looking for help here!!! Can we filter the below log data into CSV format ? 1 2 3 4 5 6 7 8 timestamp INFO <text > - Some text (1 Reply)
Discussion started by: MohSalNiz
1 Replies

2. Shell Programming and Scripting

Can we filter the below log data into CSV format?

HI , I m looking for help here!!! Can we filter the below log data into CSV format ? timestamp INFO <text > - Some text Drive .. Need a format of separate field such as 1 2 3 4 ... (2 Replies)
Discussion started by: MohSalNiz
2 Replies

3. Shell Programming and Scripting

Format DATA

Input File AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS SILVER,12287.99,3293.98,6946.02 AU01NAS002,FCNVX133800117,AU01_Melbourne_Australia,ATT,Internal,NAS ARCHIVE,12287.99,3327.12,6912.87... (6 Replies)
Discussion started by: greycells
6 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

How to get data in a specified format

Hii , I have a huge set of data stored in file a.dat as shown below a.dat: 081276A BURMA Date: 1976/ 8/12 Centroid Time: 23:26:51.8 GMT Lat= 26.55 Lon= 97.12 Depth= 15.0 Half duration= 2.2 Centroid time minus hypocenter time: 5.6 Moment Tensor: Expo=24 7.840 -2.440... (4 Replies)
Discussion started by: reva
4 Replies

6. Shell Programming and Scripting

getting the data in some format

HI i am writing a shell script to generate some files having data in some format. for this i am using awk -F":" '{printf("%-20s:%-20s:%-20s:%-20s:%-15s:%-3s:%-19s:%-2s:%-20s:%-15s:%-2s\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)}' $DIALPBIN/temp1.txt > ${DIALPBIN}/temp2.txt this helps in... (1 Reply)
Discussion started by: priyanka3006
1 Replies

7. UNIX for Dummies Questions & Answers

Help me to format this data please

Good day, I have a script on each machine on our network that will say the computer name and the number of updates needed. Then the script will send a file via scp to a network share with the title hostname.local The contents of the file would be: hostname N (with N being the number of... (11 Replies)
Discussion started by: glev2005
11 Replies

8. UNIX for Dummies Questions & Answers

Please help me format this data

STMC429 (192.168.171.72) 2008-11-24 14:18:09.412 softwareupdate Loading CatalogURL http://creativesus.conair.lan:8088/index.sucatalog No new software available. There are no updates to install STMC444 (3) (192.168.171.116) 2008-11-24 14:14:31.771 softwareupdate Loading CatalogURL... (4 Replies)
Discussion started by: glev2005
4 Replies

9. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies

10. Shell Programming and Scripting

format data

i have this data: GREEN LIST : 12321 34534 GREEN LIST : 45645 --- 23423 WHITE LIST : 23479 34534 75483 76924 12345 --- 12351 56778 --- 23330 GREEN LIST : 23567 the output must be: GREEN LIST : 12321 GREEN LIST : 34534 GREEN LIST : 45645 --- 23423 (2 Replies)
Discussion started by: inquirer
2 Replies
Login or Register to Ask a Question