|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
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 |
| Sponsored Links | ||
|
|
#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]
}'...result is... Code:
arr[2]=timestamp arr[3]=priority arr[4]=log message |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thank Ygor....It worked.
It would be helpful if you could explain the split regular expression |
|
#4
|
||||
|
||||
|
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl: How to read from a file, do regular expression and then replace the found regular expression | jessy83 | Programming | 1 | 12-05-2011 03:10 PM |
| Integer expression expected: with regular expression | ketkee1985 | Shell Programming and Scripting | 3 | 03-14-2011 02:49 PM |
| Query Regarding Regular Expression | Shell_Learner | Shell Programming and Scripting | 7 | 03-24-2009 09:41 AM |
| Regular expression query in AWK | omprasad | Shell Programming and Scripting | 10 | 01-11-2008 04:26 PM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |
|
|