- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk/sed script question
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
09-17-2002 06:41 AM
09-17-2002 06:41 AM
One additional situation is there a way that it could be multiple search strings ex: response: 2 and starting: 3...
This needs to be in a shell script, I am from the old school and havent found time to get proficient with Perl although I do a little. I can write them faster in shell.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 06:56 AM
09-17-2002 06:56 AM
Re: awk/sed script question
I don't understand your first question. What is the meaning with printing a line to a file and delete it at the same time ?
You can use multiple search strings with grep
"grep -e "response: 2" -e "starting: 3"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:01 AM
09-17-2002 07:01 AM
Re: awk/sed script question
/response: 2/{print $0 >/tmp/otherfile;next}
/response: 3/{print $0 >/tmp/otherfile;next}
{print}
Then ran the following-
awk -f scan.awk yourinput >/tmp/remain.txt
Then /tmp/otherfile will have the "response" lines and /tmp/remain.txt would have the lines that are not "reponse" lines.
HTH
(by the way- perl is worth the investment to learn...)
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:02 AM
09-17-2002 07:02 AM
Re: awk/sed script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 07:07 AM
09-17-2002 07:07 AM
Re: awk/sed script question
you can use sed | grep | awk | perl for this
e.g. supressing lines containing string "time"
sed '/time/d' /etc/services
You can use several expressions either by using multiple -e flags, or joining statements by ';'
This sould work for all parsers.
Afaik, you need to redirect the output in a new file unless you use Perl where you can use Perl's "in place edit" flag "-i
please, type "perldoc perlrun"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 09:52 AM
09-17-2002 09:52 AM
Solutionthis will do what you want:
awk '{if ($0 ~ /^response: 2$/) {print > "errorlog"} else {print}}' input
Matching lines are printed to the file "errorlog" while
non-matching lines are printed to stdout, which you
can redirect as appropriate.
Note that this leaves the original file intact. (Don't try
to redirect the output of the awk command to the input
file.) If you're operating on a flat text file I don't see any
way of actually "deleting" a line in the file without doing
any copying.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2002 11:52 AM
09-17-2002 11:52 AM
Re: awk/sed script question
1. Is this file open by any application when your trying to move lines to the error file? If so, good luck unless you can get the file to let go of this big file while your edit runs.
2. C and Perl would both be easy, as your going to open 2 files, and copy a string from file1 to file2, then replace the string in file1 with nothing.
awk, sed, and grep can not work with the file as is, as they are stream based editors. you will have to redirect output to a different location.
You would have to work with ed (I think) to in line edit the file, and even then if the file is open by another application you will have a hard time.
Hope the logic helps, and sorry I cant give a magic bullet.
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2002 07:26 AM
09-18-2002 07:26 AM
Re: awk/sed script question
perl -ni -e 'BEGIN{open ERRORS, ">error.rpt"} if ( /response: 2/ || /starting: 3/ ) {print ERRORS;next}print' your_BIG_text_file
This does an in-place edit of your_BIG_text_file, and creates an error.rpt file. If you have any doubts, then be safe and add extensions to the -i option above.
Cheers,
Leslie