- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- awk 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
11-22-2005 07:21 AM
11-22-2005 07:21 AM
awk problem
awk '/abc|cde/ END{ print "--->" $1}' file
awk: cmd. line:1: /abc|cde/ END{ print "--->" $1}
awk: cmd. line:1: ^ parse error
I got parse error...why?
hmmm..
thank u
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:34 AM
11-22-2005 07:34 AM
Re: awk problem
This works for me as written (and I cut-and-pasted from this post).
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:38 AM
11-22-2005 07:38 AM
Re: awk problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:39 AM
11-22-2005 07:39 AM
Re: awk problem
Could you have an unprintable character in the command?
Rod Hills
- Tags:
- unprintable chars
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:40 AM
11-22-2005 07:40 AM
Re: awk problem
Enter "alias" and look to see if awk is defined.
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:41 AM
11-22-2005 07:41 AM
Re: awk problem
very change.....
I am using linux system, does it matter?
awk is just awk right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:44 AM
11-22-2005 07:44 AM
Re: awk problem
The history of awk includes a version called "new awk" or "nawk", then you have the gnu version.
Although your line is very simple and should be runable. Try replacing the "--->" with just "###". In case the ">" is being processed by awk for file redirection.
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:46 AM
11-22-2005 07:46 AM
Re: awk problem
Well, 'awk' is 'awk' just like UNIX is UNIX. There *ARE* variations. You might see if you have a "new" awk --- 'nawk'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:47 AM
11-22-2005 07:47 AM
Re: awk problem
I suspect that if you remove the 'END' your script will run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:54 AM
11-22-2005 07:54 AM
Re: awk problem
gawk '/abc|cde/ END { OFS=":", print "**" $1}' file
thank you for trying...
maybe gnu awk works funny..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 07:59 AM
11-22-2005 07:59 AM
Re: awk problem
Try adding a semicolon after the regular expression and before the END block.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 08:02 AM
11-22-2005 08:02 AM
Re: awk problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 08:14 AM
11-22-2005 08:14 AM
Re: awk problem
see below
awk '/abc|cde/; END{ print "--->" $1}' file
abc test
cde test
--->test
awk '/abc|cde/ END{ print "--->" $1}' file
awk: cmd. line:1: /abc|cde/ END{ print "--->" $1}
awk: cmd. line:1: ^ parse error
awk '/abc|cde/ { print "--->" $1}' file
--->abc
--->cde
the last one is the right answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 08:24 AM
11-22-2005 08:24 AM
Re: awk problem
The last one is the CORRECT result based on what you wrote. The inference is to print lines that match the regular expresssion. Then, the END block is executed to print the "--->" and the first field of the last record processed.
If all you want is to print "--->" in front of matches do:
# awk '/abc|cde/ { print "--->" $1}' file
Of course, this assumes that the first field ($1) is what you want to point at.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 08:29 AM
11-22-2005 08:29 AM
Re: awk problem
I ended up using BEGIN..and rewrote my awk statement....
I will assign everyone some points for helping out!!
thank you very much AGAIN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 08:32 AM
11-22-2005 08:32 AM
Re: awk problem
Even your example is not clear because your input file is so sparse. With only the last line left as input, it's not easy to follow your expectations.
One trick would be to use "{exit}" as soon as a pattern match is found. The exit function imediately triggers the END block (if it exists).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2005 11:16 AM
11-22-2005 11:16 AM
Re: awk problem
I realized that I should give a sample file and a sample output, then it will much better.
next time!!
thanks all anyway!!