- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: passing script variable in awk .
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 12:09 AM
тАО07-17-2009 12:09 AM
passing script variable in awk .
I want to pass a script variable in to the awk command. The script variable is a message string having blank spaces.
$BANNER="Authorized users only. All activity may be monitored and reported."
The awk command is
ND_BANNER=`echo $BANNER |sed 's/\./\+/g'`
NB_BANNER=`echo $ND_BANNER |sed 's| |_|g'`
cat $FILE | awk VAR="${NB_BANNER}" 'BEGIN{ FS=":" ;OFS=":" };{ if($1~"^[ ]*Dtlogin.*greeting\.persLabelString"){ sub("+"," ",VAR); $2=" "VAR;}{print;}}'
I am replacing blank space with "_" sign and "." with "+".
I am getting following error.
syntax error The source line is 1.
The error context is
>>> VAR=Authorized_users_only._All_activity_may_be_monitored_and_reported+ <<<
awk: Quitting
The source line is 1.
I cannot find out why this is giving error.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 02:55 AM
тАО07-17-2009 02:55 AM
Re: passing script variable in awk .
NB_BANNER=$(echo $BANNER | sed -e 's/\./\+/g' -e 's| |_|g')
awk -v VAR="${NB_BANNER}" '
BEGIN{ FS=":" ; OFS=":" }
{ if($1~"^[ ]*Dtlogin.*greeting\.persLabelString"){
sub("\+", " ", VAR)
$2=" " VAR
}
{print}
}' $FILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 03:12 AM
тАО07-17-2009 03:12 AM
Re: passing script variable in awk .
Thanks for your reply.
Sorry , my mistake .
I did changes in the above command
NB_BANNER=$(echo $BANNER | sed -e s/\./11/g' -e 's| |00|g')
cat "/etc/dt/config/C/Xresources" | awk -v VAR="${NB_BANNER}" 'BEGIN{ FS=":" ;OFS=":" };
{
if($1~"^[]*Dtlogin.*greeting\.persLabelString")
{ sub("00"," ",VAR);
sub("11"," ",VAR);
$2=" "VAR;
}
{print;}
}'
I just used 00 for space and 11 for ".".
It gives following error message
awk: There is a regular expression error.
?, *, or + not preceded by valid regular expression
The source line number is 1.
The error context is
BEGIN{ FS=":" ;OFS=":" };{ if($1~"^[ ]*Dtlogin.*greeting\.persLabelString"){ print VAR ;sub("+"," >>> ",VAR) <<<
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 03:39 AM
тАО07-17-2009 03:39 AM
Re: passing script variable in awk .
You collapsed the space within '[ ]'. Instead of:
if($1~"^[]*Dtlogin.*greeting\.persLabelString")
...you should have:
if($1~"^[ ]*Dtlogin.*greeting\.persLabelString")
The use of '[ ]' makes a space character more clearly distinguishable in 'awk'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 03:56 AM
тАО07-17-2009 03:56 AM
Re: passing script variable in awk .
Thanks for reply.
I inserted a space in those brackets .
NB_BANNER=$(echo $BANNER | sed -e s/\./11/g' -e 's| |00|g')
cat "/etc/dt/config/C/Xresources" | awk -v VAR="${NB_BANNER}" 'BEGIN{ FS=":" ;OFS=":" };
{
if($1~"^[ ]*Dtlogin.*greeting\.persLabelString")
{ sub("00"," ",VAR);
sub("11"," ",VAR);
$2=" "VAR;
}
{print;}
}'
but it is giving same result , same error message
after replacing correctors , the banner string looks like this
Authorized00users00only1100All00activity00may00be00monitored00and00reported11
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 04:33 AM
тАО07-17-2009 04:33 AM
Re: passing script variable in awk .
awk: There is a regular expression error.
?, *, or + not preceded by valid regular expression
If you look at my changes and my reply you'll see I already told you I fixed it.
awk takes ERE and you need to quote the naked "+".
If you format ALL of your awk programs with separate lines like I do, it points right at it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2009 08:00 AM
тАО07-17-2009 08:00 AM