- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk Experts need assistance.
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
10-21-2002 11:26 AM
10-21-2002 11:26 AM
I have this monthly file 3million+ lines and I need to break it down into two files, lets say good.file and bad.file
The data looks like this
request:
response: 1wwwww@lafn.org
request:
response: 2 xxxxxxxxx@aya.yale.edu not
found
request:
response: 1 zzzzzz@dol.net
Every entry will have two lines, the first line is requesting a forwarding address, the second line is the return from the database with either the forwarding address line response:1 or a not found record response: 2. I am writing a monthly report of totals but I need to separate the two types to do further information gathering. So I would like to take the main file and separate it into two files with the request record and the matching reponse 1 or 2 record. One file for request and response 1 records and the other file request and response 2 records
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 11:42 AM
10-21-2002 11:42 AM
Re: Awk Experts need assistance.
'/response/ && $2==2 {print $3}' infile > bad
'/response/ && $2==1 {print $3}' infile > good
or if you just want totals
' BEGIN{good=0; bad=0}; /response/ && $2==1 {good=good+1}; /response/ && $2==2 {bad=bad+1}; END {print "good", good, "bad", bad}' infile
my perl is not good enough to just write a script without testing it first.
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 11:48 AM
10-21-2002 11:48 AM
Re: Awk Experts need assistance.
Try this:
#!/usr/bin/sh
awk '/request/ {X=$0}
{if (/response: 1/) {print X"\n"$0 >> "/tmp/type1"}}
{if (/response: 2/) {print X"\n"$0 >> "/tmp/type2"}}
' myinput
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 11:57 AM
10-21-2002 11:57 AM
SolutionFor consistency of style, I would amend my first post to this:
#!/usr/bin/sh
awk '/request/ {X=$0}
/response: 1/ {print X"\n"$0 >> "/tmp/type1"}
/response: 2/ {print X"\n"$0 >> "/tmp/type2"}
' myinut
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 12:05 PM
10-21-2002 12:05 PM
Re: Awk Experts need assistance.
Thanks James, (got to be in the name). Your first post had me with the good old awk errors of bail out and syntax errors. But your second post worked like a charm...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2002 12:45 PM
10-21-2002 12:45 PM
Re: Awk Experts need assistance.
Here is a quick way to do it in Perl, but I am using shell to split the lanes.
perl -n00e '
if ( /response: 1/ )
{
print STDOUT;
}
elsif ( /response: 2/ )
{
print STDERR
}
' myinut 1> good 2> bad
This reads your file in "paragraph mode" and printing to the desired filehandle.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 04:36 AM
10-22-2002 04:36 AM
Re: Awk Experts need assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 05:14 AM
10-22-2002 05:14 AM
Re: Awk Experts need assistance.
/^[^ ]*$/{
N
s/\n */ /
}
save this and run sed against your file.
cat file | sed -f scriptname
> newfilename
This will take your original file and concatenate its 2 line output to one line.
Then you should be able to use grep to get what you want
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 07:54 AM
10-22-2002 07:54 AM
Re: Awk Experts need assistance.
I did a cut 'n' paste from your original post, and ran it:
----------------------------------------------------
$ cat myinut
request:
response: 1wwwww@lafn.org
request:
response: 2 xxxxxxxxx@aya.yale.edu not
found
request:
response: 1 zzzzzz@dol.net
$ head -1000 good bad
good: No such file or directory
bad: No such file or directory
$ perl -n00e '
> if ( /response: 1/ )
> {
> print STDOUT;
> }
> elsif ( /response: 2/ )
> {
> print STDERR
> }
> ' myinut 1> good 2> bad
$ head -1000 good bad
==> good <==
request:
response: 1wwwww@lafn.org
request:
response: 1 zzzzzz@dol.net
==> bad <==
request:
response: 2 xxxxxxxxx@aya.yale.edu not
found
$
----------------------------------------------------
Perl doesn't require a semi-colon if its the last statement of a BLOCK.