- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk script problem
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
03-13-2001 10:19 AM
03-13-2001 10:19 AM
I type this on command line and get the desired output
#cat /var/adm/syslog/syslog.log |awk '$1 == "Mar" && $2 == "12" {print}'
This will print messages for Mar 12
I put this in script called as chklog, and run it like "chklog Mar 12"and it does not work.
h=$1
k=$2
cat /var/adm/syslog/syslog.log |awk '$1 == "$h" && $2 == "$k" {print}'
nothing prints.
Any suggestion
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 10:32 AM
03-13-2001 10:32 AM
Re: awk script problem
Try
h=$1
k=$2
awk '$1 == "$h" && $2 == "$k" {print $0}' /var/adm/syslog/syslog.log
...Madhu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 10:56 AM
03-13-2001 10:56 AM
Re: awk script problem
It does not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 10:58 AM
03-13-2001 10:58 AM
Re: awk script problem
#!/bin/sh
#
print -n "Enter 3char Month: "
read mon
print -n "Enter the day: "
read day
awk ' BEGIN {
while ( "cat '/var/adm/syslog/syslog.log' " | getline ) {
if ( $1 ~ '$mon' && $2 ~ '$day' ) print $0 }
} ' echo $0
This will allow you to select ANY day and have it echo to the screen...
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 11:00 AM
03-13-2001 11:00 AM
Re: awk script problem
before the if ($1 ... statement
enter on a line by itself
entries++
Sorry 'bout that,
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 11:03 AM
03-13-2001 11:03 AM
Solutioncat /var/adm/syslog/syslog.log | awk -v h=$1 -v k=$2 '$1==h && $2==k {print}'
The -v sets awk variables h and k to $1 and $2 (parameters on your shell script). The awk script can then compare $1 to h and $2 to k to look for matches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2001 11:10 AM
03-13-2001 11:10 AM
Re: awk script problem
Try this:
# h=Mar
# k=12
# cat /var/adm/syslog/syslog.log|awk -v h=$h -v k=$k '$1==h && $2==k {print}'
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2001 10:40 AM
03-15-2001 10:40 AM
Re: awk script problem
Try the following:
h=\$1==\"$1\"
k=\$2==\"$2\"
awk "($h) && ($k) {print}"
This does work fine for me.
The single quote (') versus the double quote (") and backslashing characters (prefixing with \) can get very confusing, good luck in the future.