- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: search string in awk program
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
Forums
Discussions
Discussions
Discussions
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
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
11-06-2001 12:37 PM
11-06-2001 12:37 PM
I have to look for a particular charcter(#) in an awk variable (in awk program) and take decision based on it.
for e.g (Part of my awk program)
-----------------
if ( job_code != "" && script != "" && job_type != "" ) {
job_code1=system("echo "job_code"|grep \"#\"")
if (job_code1 != "" )
{
split(job_code,tag1,"#")
job_code2=tag1[1]
split(job_code2,tag2,"=")
job_code=tag2[1]
print "#/job_code="job_code"@"tolower(dbsid)"#hold#"
}
else {
print "#/job_code="job_code"@"tolower(dbsid)
}
print "#/job_type="job_type
print "#/script="script
---------------
for some reason, the variable job_type1 always not null. I have a suspicion that the command might be wrong. Can some body help me out. Thanks in adv.
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2001 12:53 PM
11-06-2001 12:53 PM
Re: search string in awk program
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2001 12:53 PM
11-06-2001 12:53 PM
Re: search string in awk program
The value of 'job_code1' will be the exit status of the 'system' command -- either <0> or <1>. Does that help?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2001 01:17 PM
11-06-2001 01:17 PM
SolutionWhy are you using grep within awk when awk can do pattern matching itself? Moreover, you are send a CONSTANT string into grep. You are always going to get the same answer!
A better approach might be:
if ($0 ~ /#/)
{
printf("I found it\n")
}
else
{
printf("Not there\n")
}
or if you already have your data in a named variable
if (job_code ~ /#/)
{
}
or
if (job_code !~ /#/) # does not match
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2001 01:31 PM
11-06-2001 01:31 PM
Re: search string in awk program
a great way to parse through a text file and use a variable in an awk statement to identify the line to perform a substitution on is to use the ENVIRON function. For example, say you have a file called FILENAME. You wanted to search for all lines that had the contants of the HOST variable in its first field and based on that perform a substitution.
cat $FILENAME | awk -v var1="old" -v var2="new" '
(
if ($1 == ENVIRON["HOST"])
{
sub(var1,var2);
}
} '
Hope this helps!
Tony