Visit Our UNIX and Linux User Community


Format Ouput


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format Ouput
# 1  
Old 12-08-2011
Format Ouput

I have this input file

Code:
 
Switch 0; Sun Sep 11 12:40:53 2011 EDT (GMT+4:00)
12:40:53.159984 SCN Port Offline;g=0x1e4b6                  A2,P0  A2,P0  379   NA    
12:40:53.159991 *Removing all nodes from port               A2,P0  A2,P0  379   NA    
18:45:31.326604 Port Elp engaged                            A2,P1  A2,P0  4     NA    
18:45:31.326609 SCN Port F_PORT                             A2,P1  A2,P0  4     NA    
18:45:31.326616 *Removing all nodes from port               A2,P0  A2,P0  4     NA    
Switch 0; Mon Sep 12 04:12:22 2011 EDT (GMT+4:00)
04:12:22.729711 SCN Port Offline;g=0x1e4ce                  A2,P0  A2,P0  302   NA    
04:12:22.729719 *Removing all nodes from port               A2,P0  A2,P0  302   NA    
04:14:12.719175 SCN LR_PORT (0);g=0x1e4ce                   A2,P0  A2,P0  302   NA    
04:14:12.720048 SCN Port Online;g=0x1e4ce                   A2,P0  A2,P1  302   NA


Basically i want the date before each line like this

Code:
 
Switch 0; Sun Sep 11 12:40:53 2011 EDT (GMT+4:00)
Sun_Sept11_2011-12:40:53.159984 SCN Port Offline;g=0x1e4b6                  A2,P0  A2,P0  379   NA    
Sun_Sept11_2011-12:40:53.159991 *Removing all nodes from port               A2,P0  A2,P0  379   NA    
Sun_Sept11_2011-18:45:31.326604 Port Elp engaged                            A2,P1  A2,P0  4     NA    
Sun_Sept11_2011-18:45:31.326609 SCN Port F_PORT                             A2,P1  A2,P0  4     NA    
Sun_Sept11_2011-18:45:31.326616 *Removing all nodes from port               A2,P0  A2,P0  4     NA    
Switch 0; Mon Sep 12 04:12:22 2011 EDT (GMT+4:00)
Mon_Sep12_2011-04:12:22.729711 SCN Port Offline;g=0x1e4ce                  A2,P0  A2,P0  302   NA    
Mon_Sep12_2011-04:12:22.729719 *Removing all nodes from port               A2,P0  A2,P0  302   NA    
Mon_Sep12_2011-04:14:12.719175 SCN LR_PORT (0);g=0x1e4ce                   A2,P0  A2,P0  302   NA    
Mon_Sep12_2011-04:14:12.720048 SCN Port Online;g=0x1e4ce                   A2,P0  A2,P1  302   NA


Thanks
# 2  
Old 12-08-2011
Code:
awk '/^Switch/{s1=$3;s2=$4;s3=$5;s4=$7}!/^Switch/{$0=s1"_"s2""s3"_"s4"-"$0}1' input

This User Gave Thanks to bartus11 For This Post:

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ouput not in file2 using awk?

Hi All, Seeking for your assistance on how to ouput the file which is not match in file 1 and file 2 using awk. I tried NR=FNR but it's not working, it will only show the match record. Ex. File1 abc def ghi File2 23a gd abc Output: abc (2 Replies)
Discussion started by: znesotomayor
2 Replies

2. Shell Programming and Scripting

Use of awk or sed to filter out the ouput

Hi, i am trying to get the system model with the help of awk : $ prtconf | awk '/^System Model/' System Model: IBM,8408-E8D but i want just the below outout that is command should chk for pattern <IBM,> and remove it from the final output : System Model:8408-E8D Can... (2 Replies)
Discussion started by: omkar.jadhav
2 Replies

3. Shell Programming and Scripting

<< Filter and Format the ouput >>

Hi All, I have a output like below $ cat aa.lst Value of output parameters --------------------------------------- Parameter Name : SNAPSHOTTIMESTAMP Parameter Value : 2014-01-07-15.21.50.022423 Parameter Name : DATABASESIZE Parameter Value : 96178176 ... (2 Replies)
Discussion started by: kamauv234
2 Replies

4. Shell Programming and Scripting

Parse ouput within an AWK Command

I have a script that I am writing to parse the output of information from a command. Here is one of the lines of the output exported into the variable OUTPUT: export OUTPUT=”name_of_system,0,5,9,55,ip_address,another_value,/PATH/OF/A/VALUE/I/NEED" I can get the output I need... (5 Replies)
Discussion started by: jake0391S
5 Replies

5. Shell Programming and Scripting

Append ouput in a single line

Hi Guys, I need to append some data to a new file, but i need to make sure that when i use to >> command again.I dont go to the new line. i append the data on the same line. Please help regarding the same. Thanks in advance..!!! (3 Replies)
Discussion started by: jaituteja
3 Replies

6. Shell Programming and Scripting

View ouput as a file

Hi all , I have a view in teradata , the ouput of that view have to be stored as a file with delimitere as '|'.Is there any possibility of doing this in unix ? Thanks in advance , Vinoth (6 Replies)
Discussion started by: vino.paal
6 Replies

7. Shell Programming and Scripting

how can we perform calculation on the ouput of the commnad

Hello I am very new to unix scripting. The below is the ouput of my one command, now i want to use the two below values 611 and 572 from the output of the command . in the ouput i want 39 which would be come by subtracting 572 to 611. please suggest how can we perform subtraction of... (6 Replies)
Discussion started by: singhald
6 Replies

8. Shell Programming and Scripting

Cannot redirect ouput?????

Hello experts, I'm testing a program that prints error message to the screen. I want to redirect the output to a file using >. but the message only prints on screen and not writing to the file, Any suggestion on what I might try? (3 Replies)
Discussion started by: minifish
3 Replies

9. Shell Programming and Scripting

capture the ouput!

Hi, my perl script is calling another external java program. The Java in turn prints out a string. how can I capture the string. ------------------ #!/usr/bin/perl print "Content-type:text/html\n\n"; use CGI; $query = new CGI; $theCookie = $query->cookie('someCookie'); $user =... (0 Replies)
Discussion started by: azmathshaikh
0 Replies

10. UNIX for Dummies Questions & Answers

Red Hat - ouput capture

Red Hat 7.2 On command line.. i need to ouput or capture just.. CPE3236313839393 Fri Nov 1 00:05 - 00:05 (00:00) the time inside the brackets (00:00) ... i havea list of about a hundred from sperate dates in a long file. I need to some how grep or i dunno all times from Nov 1 and... (3 Replies)
Discussion started by: juxtaman
3 Replies

Featured Tech Videos