- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl (one line) search string and remove line from...
Operating System - HP-UX
1820254
Members
2584
Online
109622
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО04-14-2011 12:02 AM
тАО04-14-2011 12:02 AM
hello,
i am not a perl expert and try in unix following perl one liner, hope correct.
example file with field seperator : remove_one_line.txt
1;line1_field2;1
2;line2_field2;2
3;line3_field2;3
export remove_string="line1_field2"
perl -i.old -ne 'print unless /$ENV{'remove_string'}/' remove_one_line.txt
i am not a perl expert and try in unix following perl one liner, hope correct.
example file with field seperator : remove_one_line.txt
1;line1_field2;1
2;line2_field2;2
3;line3_field2;3
export remove_string="line1_field2"
perl -i.old -ne 'print unless /$ENV{'remove_string'}/' remove_one_line.txt
Solved! Go to Solution.
- Tags:
- Perl
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2011 03:33 AM
тАО04-14-2011 03:33 AM
Re: perl (one line) search string and remove line from file
Replace the single quotes aroung remove_string with double quotes and it will work:
perl -i.old -ne 'print unless /$ENV/"remove_string"}/' remove_one_line.txt
Note that if remove_string is something like "xyz", it will remove all lines that have "xyz" anywhere in the line, so not only
2;xyz;2
but also
3;uvwxyzABC;3
perl -i.old -ne 'print unless /$ENV/"remove_string"}/' remove_one_line.txt
Note that if remove_string is something like "xyz", it will remove all lines that have "xyz" anywhere in the line, so not only
2;xyz;2
but also
3;uvwxyzABC;3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2011 03:44 AM
тАО04-14-2011 03:44 AM
Solution
Hi:
So, your question is? Yes, the script will remove a matched line.
You can satisfy yourself by building a 'remove_one_line.txt' file and dropping gthe '-i.old' argument. When you are satisfied, and wish to update your file, add that back.
While the command works as you want, you can shorten things to:
# remove_string=line1_field2 perl -i.old -ne 'print unless /$ENV{remove_string}/' remove_one_line.txt
That is, there is no need to 'export'; simply declare the variable and value on the same line with whitespace (*not* a semicolon) before 'perl ...'.
Regards!
...JRF...
So, your question is? Yes, the script will remove a matched line.
You can satisfy yourself by building a 'remove_one_line.txt' file and dropping gthe '-i.old' argument. When you are satisfied, and wish to update your file, add that back.
While the command works as you want, you can shorten things to:
# remove_string=line1_field2 perl -i.old -ne 'print unless /$ENV{remove_string}/' remove_one_line.txt
That is, there is no need to 'export'; simply declare the variable and value on the same line with whitespace (*not* a semicolon) before 'perl ...'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2011 03:56 AM
тАО04-14-2011 03:56 AM
Re: perl (one line) search string and remove line from file
thank you very much, it work's perfect
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP