![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regular expression query in AWK | omprasad | Shell Programming and Scripting | 10 | 01-11-2008 02:26 PM |
| Regular expression | maxvirrozeito | UNIX for Dummies Questions & Answers | 1 | 12-14-2007 05:02 AM |
| What does the regular expression ['(^[^~]+~).*'] mean? | anupamar | High Level Programming | 2 | 10-29-2007 01:41 AM |
| help in regular expression | Rakesh Ranjan | High Level Programming | 5 | 10-25-2006 10:00 AM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 07:59 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a varable(var1) in a AWK script that contain data in the following format
[timestamp] [priority] - [log message] I need to extract timestamp,priority and log message.I can extract these by using split function but i don't want to use it, since i want to extract it in one go. I have some difficulties in doing it using Regular expression using a single statement. Can anybody help me on this |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Try...
Code:
awk 'BEGIN{
var = "[timestamp] [priority] - [log message]"
n = split(var, arr, /(^\[)|(\] -? ?\[)|(\]$)/)
for (x=2; x<n; x++)
printf "arr[%d]=%s\n", x, arr[x]
}'
Code:
arr[2]=timestamp arr[3]=priority arr[4]=log message |
|
#3
|
|||
|
|||
|
Thank Ygor....It worked.
It would be helpful if you could explain the split regular expression |
|
#4
|
||||
|
||||
| Google The UNIX and Linux Forums |