![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Regular expression | maxvirrozeito | UNIX for Dummies Questions & Answers | 1 | 12-14-2007 08:02 AM |
| error: initializer expression list treated as compound expression | arunchaudhary19 | High Level Programming | 12 | 11-16-2007 06:44 AM |
| regular expression...help!! | andy2000 | UNIX for Dummies Questions & Answers | 6 | 07-18-2007 05:10 PM |
| regular expression help | mac2118 | Shell Programming and Scripting | 5 | 03-01-2005 07:45 AM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 10:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
nawk empty regular expression error
Hello, All.
please help me with this problem. i need to use variable as regular expression. some thing like this: BEGIN { RS="\n"; ORS="\n"; reg_exp = ".+Dec.+"; # i mean that regular expression is any symbol before "Dec" and any symbol after it. For example <Worksheet ss:Name="December"> } $0 ~ reg_exp { print $0 next } and i get: error empty regular expression. if i try like this $0 ~ /.+Dec.+/{ print $0 next } everything is all right. thanks in advance |
|
||||
|
thank you for your reply.
it works. but actually a get a reg_exp during running the script like this $0 ~ /.+<Worksheet ss:Name.+/{ reg_exp = substr($0,22,3) # i can print reg_exp. the value of reg_exp is "Dec" print $0 next } and then i use this reg_exp. the string which hold "<Worksheet ss:Name" is before string which i compare with reg_exp and i stell get error |
|
||||
|
Quote:
|
|
||||
|
Quote:
You don't need the BEGIN{} part as it is the default action taken by nawk. Code:
nawk '{
regexp=".+Dec.+"
if ($0 ~ regexp)
print $0
}' file
|
|
||||
|
Hello, All.
i had problem with connection yesterday and could not unswer. Thanks a lot. i've already solved my problem. my problem was: i was trying to use reg_exp before i assign this variable. my script was: BEGIN { RS="\n"; ORS="\n"; reg_exp=""; } $0 ~ /.+<Worksheet ss:Name.+/{ reg_exp = substr($0,22,3) print $0 next } $0 ~ reg_exp { print $0 print "TEST" next } and input file was about: Record_1 Record_2 Record_3 ....... Record_n <Worksheet ss:Name="December"> Record_n+2 ..... Bye |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|