- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sed script
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
02-01-2005 03:14 PM
02-01-2005 03:14 PM
I have been working with this sed but can't get it work properly.
I have a file - a long one - with data and need to grep the phrases 2 lines after the keyword "var_out" hence :-
USIM=`grep -E -n "var_out" filename.txt | awk '{print $1+2}'`
This will result in number the line numbers of the data such as :-
20 43 56 75 88
Later I will use sed to grep all the phrases in the line numbers obtained from the first script.
sed -n "$USIMp" filename.txt > result.txt
But it doesn't work.
Can you please help.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2005 04:39 PM
02-01-2005 04:39 PM
Solutionwill look see if a variable named USIMp exists, which we assume doesn't.
Usually you would use curly brackets like-
sed -n "${USIM}p" filename.txt >result.txt
so that will evaluate to
sed -n "20 43 56 75 88p" filename.xt >result.txt
But this probabily isn't going get what you want.
You could try-
grep -E -n "var_out" filename.txt | awk '{printf "%dp\n",$1+2}' >/tmp/mylist
sed -n -f /tmp/mylist filename.txt >result.txt
Or perl can do it-
perl -n -e '$n=$.+2 if /var_out/; print $_ if $n == $.' filename.txt >result.txt
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2005 06:10 PM
02-01-2005 06:10 PM
Re: Sed script
Great! It really works for me.
I will stick with the awk and sed for the time being. Perl is too complex for me :)
Many thanks for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2005 07:54 PM
02-01-2005 07:54 PM
Re: Sed script
if you want to pull out the line following 2 after the key_word "var_out" try:
sed -n '/var_out/n;n;p;' filename.txt
The n;n;p; means next;next;print;
Is this of any help?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2005 08:17 PM
02-01-2005 08:17 PM
Re: Sed script
It won't work that way. The output will include some unwanted lines.