- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk script using system COMMAND
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
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
тАО10-08-2002 11:42 AM
тАО10-08-2002 11:42 AM
Here is the line that I'm having a problem with.
COMMAND=("grep -q " substr($0,53,4) " /tmp/reffile")
The above line works, but it needs to have a variable for the file name, based on SITECODE. I tried $REFFILE, but it didn't work. This script will use different DATAFILE files, and REFFILE files, based on SITECODE.
See the attachment for the exact coding.
The attachment has additional comments.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 11:54 AM
тАО10-08-2002 11:54 AM
Re: awk script using system COMMAND
If you checked that thread, I posted one script purely in Shell that can be easily modified to fit your purposes. It will take care of things like this.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 12:18 PM
тАО10-08-2002 12:18 PM
Re: awk script using system COMMAND
You can pass a variable into a 'awk' script thusly:
#!/usr/bin/sh
typeset THEFILE=$1
awk -v THEFILE="$THEFILE"'
{ if ($2~/455/) {
if (substr($4,17,6)=="abcdef") {
COMMAND=("grep -q " substr($4,1,4) " "THEFILE)
if (system(COMMAND))
{print $0 "XXbb"
}
else
{print $0 "XXYY"
}
close(COMMAND)
}
else
{print $0"bbbb"
}
}
else
{print $0
}
} ' /tmp/myinput
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 01:13 PM
тАО10-08-2002 01:13 PM
Re: awk script using system COMMAND
#!/bin/sh
#
FILE=$1
VAR=$2
echo "debug: file=$FILE var=$VAR"
echo "" | awk '{
printf "this is the '"${FILE}"' file.\n"
printf "and this the '"${VAR}"' variable\n"
}'
=======================
> ./pass_vars BLAH BLEH
debug: file=BLAH var=BLEH
this is the BLAH file.
and this the BLEH variable
> ./pass_vars "BLAH BLAH" "BLEH BLEH"
debug: file=BLAH BLAH var=BLEH BLEH
this is the BLAH BLAH file.
and this the BLEH BLEH variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2002 01:29 PM
тАО10-08-2002 01:29 PM
Solution...sorry, priority interrupt. In the case you have shown, I'd simply create a procedure (function) to which you pass the value of the input file (INPFILE) and the reference file (REFFILE). This will allow you to call the 'awk' code with variable arguments. Mind you, this is but one way you can implement this.
#!/usr/bin/sh
typeset INPFILE=$1
typeset REFFILE=$2
#
function filter
{
awk -v REFFILE=$REFFILE '
{ if ($2~/455/) {
if (substr($4,17,6)=="abcdef") {
COMMAND=("grep -q " substr($4,1,4) " "REFFILE)
if (system(COMMAND))
{print $0 "XXbb"
}
else
{print $0 "XXYY"
}
close(COMMAND)
}
else
{print $0"bbbb"
}
}
else
{print $0
}
} ' $INPFILE
} #_endof_filter
#
filter $INPFILE $REFFILE
exit 0
...since the indentation will be mangled here, I've also attached the above script.
Regards!
...JRF...