- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed variable substitution NOT to match any lines?
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
тАО01-02-2003 08:45 AM
тАО01-02-2003 08:45 AM
I've got a script that defines a string, say:
x=abc123
and then modifies a file based upon a one-line sed script:
sed "1,/$x/ d" infile > outfile
...
Here is the kicker: How do I define $x so that the sed script matches NO lines? I want, under certain circumstances, for the input file to exactly match the output file.
This would be an easy extra line or two to implement, but sed probably has some very easy way to do this internally.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 09:18 AM
тАО01-02-2003 09:18 AM
Re: sed variable substitution NOT to match any lines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 09:29 AM
тАО01-02-2003 09:29 AM
Re: sed variable substitution NOT to match any lines?
Pls try this:
cat infile|sed 's/$x/ d/g' > outfile
This replace string contened in $x (abc123) by " d" string (space an letter d), note that quotes must be single.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 09:30 AM
тАО01-02-2003 09:30 AM
SolutionI don't think you can get there from here!
Assuming that you *only* change the value of $x then the best you can do is only delete the first line from the output string:
Consider:
# x=
# sed "1,/$x/d" /etc/hosts > /tmp/hosts
# diff /etc/hosts /tmp/hosts
...you will see that only the first line has been deleted.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 09:33 AM
тАО01-02-2003 09:33 AM
Re: sed variable substitution NOT to match any lines?
You will need to go with a small if statement to verify the value of 'x' and based on it use the sed statement.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 11:40 AM
тАО01-02-2003 11:40 AM
Re: sed variable substitution NOT to match any lines?
sed "1,/^$x\$/d" infile >outfile
or in perl
perl -ne "m{^$x\$} or print" infile >outfile
or in grep
grep -v "^$x\$" infile >outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-02-2003 12:57 PM
тАО01-02-2003 12:57 PM
Re: sed variable substitution NOT to match any lines?
x="1,/abc123/ d"
and sometimes
x=":"
sed "$x" infile > outfile
Thanks for the feedback, folks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-03-2003 05:03 AM
тАО01-03-2003 05:03 AM
Re: sed variable substitution NOT to match any lines?
To delete lines:
sed '/'$x'/d' infile > outfile
To substitute all lines:
sed '1,$s/'$x'/whatever/'
Hope this helps.