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
тАО03-25-2004 03:59 AM
тАО03-25-2004 03:59 AM
awk 'BEGIN { FS="|"; OFS="|" }
{ (if NF = 4 )
{ print $0 } > good_file.txt
else
{ print $0 } > bad_file.txt
} < input_file.txt
I keep getting the cryptic awk "something wrong on line 3" message. What am I missing here?
Regards,
CB
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:05 AM
тАО03-25-2004 04:05 AM
Re: Awk help
if (NF = 4)
I assume you meant a comparison rather than an assignment. Use "==".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:10 AM
тАО03-25-2004 04:10 AM
Re: Awk help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:15 AM
тАО03-25-2004 04:15 AM
Re: Awk help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:20 AM
тАО03-25-2004 04:20 AM
Re: Awk help
Is my syntax correct for the 'if' statement?
I've tried restructuring this several ways but still no success. Obviously I haven't hit the right way.
CB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:22 AM
тАО03-25-2004 04:22 AM
Re: Awk help
print [expression-list] [ > expression]
So you need to (double)quote file.txt to make it an expression. And you have the closing curly brace in the wrong place.
Try something like:
awk '{ if (NF==2) {print $0 >> "good_file.txt"} else {print $0 >> "bad_file.txt"}}'
aap
aap noot
aap noot mies
$ cat good_file.txt
aap noot
$ cat bad_file.txt
aap
aap noot mies
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:23 AM
тАО03-25-2004 04:23 AM
Re: Awk help
Next (if NF = 4) should be "if (NF == 4)".
No quotes around the filename:
awk 'BEGIN { FS="|"; OFS="|" }
{
if (NF == 4 ) print $0 > "good_file.txt"
else print $0 > "bad_file.txt"
}' < input_file.txt
should be close.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:37 AM
тАО03-25-2004 04:37 AM
Re: Awk help
# perl -aF\\\| -pe'select@F==4?STDOUT:STDERR' input_file.txt >good_file.txt 2>bad_file.txt
or
# perl -aF\\\| -ne'print{@F==4?STDOUT:STDERR}$_' input_file.txt >good_file.txt 2>bad_file.txt
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:39 AM
тАО03-25-2004 04:39 AM
Re: Awk help
I also need to replace the file name with a variable but I'm not sure it would matter.
cb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2004 04:44 AM
тАО03-25-2004 04:44 AM