![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple field separators in awk? (First a space, then a colon) | doubleminus | UNIX for Dummies Questions & Answers | 3 | 04-27-2008 04:28 PM |
| I need help counting the fields and field separators using Nawk | scrappycc | Shell Programming and Scripting | 3 | 02-06-2008 11:47 PM |
| can you redirect multiple files for input? | Matrix_Prime | UNIX for Dummies Questions & Answers | 4 | 02-27-2005 07:07 PM |
| Awk Multiple Field Separators | Tonka52 | Shell Programming and Scripting | 7 | 04-07-2004 10:37 PM |
| Output Multiple Field from dataBase file | Dennz | UNIX for Dummies Questions & Answers | 3 | 09-01-2003 01:41 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
I saw a couple of posts here referencing how to handle more than one input field separator in awk. I figured I would share how I (just!) figured out how to turn this line in a logfile:
90000000000000000000010001 name D0.90000000000103787900010001QF840840916070000007085814Y216254@D1111111111111111=1107xxxxxxxxxxxxxxx x919MENCHIES into this format: 90000000000000000000010001,name,840840916070000007085814Y216654,1111111111111111,1107,919MENCHIES I have an entire script since this is just one step in a process of turning logs into useful information, but heres the relevant portion. #Author: kinksville #Date: April 24, 2008 #Revised: April 24, 2008 #Revision: Revision 1.00 #Other files: cclookup.s, cclookup.rep #Changelog: #April 24, 2008: Initial creation of the script. # #End changelog. BEGIN { FS="[ \. QF \@D = x]+" OFS = "," } #First iteration of the @D search, stripping out the . character and inserting a OFS. /\@D/ { #Search for any line containing the string @D report2="cclookup.rep2"; #Define report2 variable. report="cclookup.rep"; #Define report variable. num_cclookup++; #Get number of auth requests. print $1, $2, $5, $6, $7, $8 > report; print $0 > report2; } #End of the @D search. The key is the fact that awk will accept a regular expression as file separator. This regexp FS="[ \. QF \@D = x]+" matches spaces, the . the string QF, the string @D, the =, and the character x. The + after the trailing bracket is the key, since that allows for 1 or more instances of any of the characters matched by the regexp. That means that x and xxxxxx are both treated as a single field separator. I still need to work on the output, since now I need to trim the name off the end of the last field. Unfortunately the number in the last field can range anywhere from 9999999 to 1 and that is the part that I want to preserve. Maybe a [^0-9]+ expression? |
| Bookmarks |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|