Sponsored Content
Full Discussion: Nawk Format
Top Forums Shell Programming and Scripting Nawk Format Post 302537496 by ther2000 on Friday 8th of July 2011 10:42:49 AM
Old 07-08-2011
Nawk Format

Hi! I have a file which I want to search daily for any line that contains the work 'Reason' and I want to take that line and put the data in a certain format using awk or nawk....I do not have gawk on my machine so it would have to be awk or nawk, or sed would work as well. Here are some examples of the input lines:

Code:
 
-07/07@04:03:34 - 10.7.23.144 : DIAG 3x3b: Reason: code 0x60, Sent by kernel-
-07/07@04:04:14 - 10.37.42.194 : DIAG 3x3b: Reason: code 0x60, Sent by kernel-
-07/07@06:50:04 - 10.7.14.854 : DIAG 0x72: Reason: FATAL MEMORY ERROR - guard band corrupt (addr:0x70e6190 size:32 owner:75(TblMgr Main)) at _mem_DeletePointer line 1737-
-07/07@08:35:28 - 10.7.62.820 : DIAG 0x72: Reason: OCP initiated reset...Rebooting from Delay Dial Option-
-07/07@10:33:14 - 10.7.23.167 : DIAG 0x72: Reason: PASSTHRU RESET MESSAGE-
-07/07@10:34:28 - 10.7.42.621 : DIAG 0x72: Reason: OCP initiated reset...Rebooting from Delay Dial Option-
-07/07@11:19:33 - 10.5.26.704 : DIAG 3x3b: Reason: code 0x11, Unmapped address, fault address: 0x00000925-
-07/07@11:19:33 - 10.7.26.704 : DIAG 3x3b: Reason: code 0x11, Unmapped address, fault address: 0x00000925-
-07/07@11:19:45 - 10.7.24.277 : DIAG 0x72: Reason: OCP initiated reset...Rebooting from Delay Dial Option-
-07/07@15:43:47 - 10.7.25.474 : DIAG 0x72: Reason: PASSTHRU RESET MESSAGE-
-07/07@15:56:38 - 10.7.65.77 : DIAG 0x72: Reason: Error! line 548 of dacct_ExitLoadClImage() in dacctrail/dacct.c-
-07/07@17:13:40 - 10.7.23.342 : DIAG 0x72: Reason: OCP initiated reset...IMAGE upgrade complete!-
-07/07@17:47:57 - 10.5.44.351 : DIAG 0x72: Reason: ERROR: dk_Reset called.-

The output I would like is to eliminate any lines that contain "OCP" or "PASSTHRU RESET" and put everything in the following format:

Date/Time,Location,Shelf,IP,Reason,Log Filename

Code:
07/07@04:03:34,-,-,10.7.23.144,DIAG 3x3b: Reason: code 0x60, Sent by kernel,$DATE/10.7.23.144
07/07@04:04:14,-,-,10.37.42.194,DIAG 3x3b: Reason: code 0x60, Sent by kernel,$DATE/10.37.42.194
07/07@06:50:04,-,-,10.7.14.854,DIAG 0x72: Reason: FATAL MEMORY ERROR - guard band corrupt (addr:0x70e6190 size:32 owner:75(TblMgr Main)) at _mem_DeletePointer line 1737,$DATE/10.7.14.854
07/07@11:19:33,-,-,10.5.26.704,DIAG 3x3b: Reason: code 0x11- Unmapped address- fault address: 0x00000925,$DATE/10.5.26.704
07/07@11:19:33,-,-,10.7.26.704,DIAG 3x3b: Reason: code 0x11, Unmapped address, fault address: 0x00000925,$DATE/10.7.65.77
07/07@15:56:38,-,-,10.7.65.77,DIAG 0x72: Reason: Error! line 548 of dacct_ExitLoadClImage() in dacctrail/dacct.c,$DATE/10.7.65.77
07/07@17:47:57,-,-,10.5.44.351,DIAG 0x72: Reason: ERROR: dk_Reset called,$DATE/10.5.44.351

The problem I am having is I want to be able to put this data into an Excel file and so I need to remove any commas that are in the 'Reason' column or else it puts them into seperate cells. Aslo, at the end where it says $DATE I want it to display a date variable that I have and then the IP address.

Last edited by ther2000; 07-08-2011 at 11:50 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

2. Shell Programming and Scripting

awk/nawk question to format a file

Hi, I am new to awk/nawk, needs help. I want to merge the rows having emplid attribute same into a single row in the following file. In actual this kind of file will have around 50k rows. Here is my input file id|emplid|firstname|dep|lastname 1|001234|test|1001|1 2|002345|test|1032|2... (7 Replies)
Discussion started by: kumar04
7 Replies

3. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

4. Shell Programming and Scripting

how to parse the file in xml format using awk/nawk

Hi All, I have an xml file with the below format. <a>111</a><b>222</b><c>333<c><d><e>123</e><f>234</f><d><e>456</e><f>789</f> output needed is 111,222,333,123,234 111,222,333,456,789 nawk 'BEGIN{FS="<|>"} {print a,b,c,e,f a="" ... (7 Replies)
Discussion started by: natalie23
7 Replies

5. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

6. Shell Programming and Scripting

NAWK: changing string-format with split

Hi all, I try to make a awk-script, which counts lines, summarized by pdf and xml. So far it works, but for sorting reasons, I'd like to change the format from the field $1 from dd-mm-yyyy to yyyy-mm-dd. This works find, but: split() and sprintf() prints its output (for no reason, the results... (2 Replies)
Discussion started by: regisl67
2 Replies

7. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

8. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

9. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

10. UNIX for Beginners Questions & Answers

Date format conversion how to change this from using nawk to awk

Hi, I have a file where I need to change the date format on the nth field from DD-MM-YYYY to YYYY-MM-DD so I can accurately sort the record by dates From regex - Use sed or awk to fix date format - Stack Overflow, I found an example using nawk. Test run as below: $: cat xyz.txt A ... (2 Replies)
Discussion started by: newbie_01
2 Replies
ucblinks(1B)                                         SunOS/BSD Compatibility Package Commands                                         ucblinks(1B)

NAME
ucblinks - adds /dev entries to give SunOS 4.x compatible names to SunOS 5.x devices SYNOPSIS
/usr/ucb/ucblinks [-e rulebase] [-r rootdir] DESCRIPTION
ucblinks creates symbolic links under the /dev directory for devices whose SunOS 5.x names differ from their SunOS 4.x names. Where possi- ble, these symbolic links point to the device's SunOS 5.x name rather than to the actual /devices entry. ucblinks does not remove unneeded compatibility links; these must be removed by hand. ucblinks should be called each time the system is reconfiguration-booted, after any new SunOS 5.x links that are needed have been created, since the reconfiguration may have resulted in more compatibility names being needed. In releases prior to SunOS 5.4, ucblinks used a nawk rule-base to construct the SunOS 4.x compatible names. ucblinks no longer uses nawk for the default operation, although nawk rule-bases can still be specifed with the -e option. The nawk rule-base equivalent to the SunOS 5.4 default operation can be found in /usr/ucblib/ucblinks.awk. OPTIONS
-e rulebase Specify rulebase as the file containing nawk(1) pattern-action statements. -r rootdir Specify rootdir as the directory under which dev and devices will be found, rather than the standard root directory /. FILES
/usr/ucblib/ucblinks.awk sample rule-base for compatibility links ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
devlinks(1M), disks(1M), ports(1M), tapes(1M), attributes(5) SunOS 5.10 13 Apr 1994 ucblinks(1B)
All times are GMT -4. The time now is 10:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy