Nawk Format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nawk Format
# 8  
Old 07-08-2011
you can get ride off the other comas by adding "s/, / /g" to the sed statement :

example :

Code:
$ echo "07/07@11:19:33,-,-,10.7.2.204 ,DIAG 0x0b: Reason: code 0x1, Unmapped address, fault address: 0x00000514,07-08-2011," | sed 's/, / /g'
07/07@11:19:33,-,-,10.7.2.204 ,DIAG 0x0b: Reason: code 0x1 Unmapped address fault address: 0x00000514,07-08-2011,

---------- Post updated at 09:58 PM ---------- Previous update was at 09:51 PM ----------

I am afraid you did not exactly tryied the code as is, maybe you did some misstyping.

Or you forgot some space in the input example you gave earlier :
indeed, the "s/ : /,/" statement would have removed the space that is before the ",DIAG" occurrence.

So i think that you should retry the code by retyping it taking care of not forgetting any comas, bracket or space.

---------- Post updated at 10:42 PM ---------- Previous update was at 09:58 PM ----------

Try this code :

Code:
sed '/OCP/d;/PASSTHRU RESET/d;/Reason/!d;s/-//g;s/  /,-,-,/;s/  / - /;s/ : /,/;s!\([0-9\.]*\),DIAG.*!&,$DATE/\1!;s/, / /g;s/\.,/,/' yourinputfile


Last edited by ctsgnb; 07-08-2011 at 06:02 PM.. Reason: code fix ... forgot to escape the dot
This User Gave Thanks to ctsgnb For This Post:
# 9  
Old 07-08-2011
Thank you so much that works great!
# 10  
Old 07-08-2011
Also consider :

Code:
$ sed '/OCP/d;/PASSTHRU RESET/d;/Reason/!d;s/-//g;s/  /,-,-,/;s/  / - /;s/ : /,/;s!\([0-9\.]*\),DIAG.*!&,'$(date +%d-%m-%Y)'/\1!;s/, / /g;s/\.,/,/' yourinputfile
07/07@04:03:3,-,-,10.7.23.144,DIAG 3x3b: Reason: code 0x60 Sent by kernel,08-07-2011/10.7.23.144
07/07@04:04:1,-,-,10.37.42.194,DIAG 3x3b: Reason: code 0x60 Sent by kernel,08-07-2011/10.37.42.194
07/07@06:50:0,-,-,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,08-07-2011/10.7.14.854
07/07@11:19:3,-,-,10.5.26.704,DIAG 3x3b: Reason: code 0x11 Unmapped address fault address: 0x00000925,08-07-2011/10.5.26.704
07/07@11:19:3,-,-,10.7.26.704,DIAG 3x3b: Reason: code 0x11 Unmapped address fault address: 0x00000925,08-07-2011/10.7.26.704
07/07@15:56:3,-,-,10.7.65.77,DIAG 0x72: Reason: Error! line 548 of dacct_ExitLoadClImage() in dacctrail/dacct.c,08-07-2011/10.7.65.77
07/07@17:47:5,-,-,10.5.44.351,DIAG 0x72: Reason: ERROR: dk_Reset called.,08-07-2011/10.5.44.351


Last edited by ctsgnb; 07-08-2011 at 06:03 PM.. Reason: code fix... i forgot to escape the dot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question