- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- pattern search and replace
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
тАО08-25-2006 04:39 AM
тАО08-25-2006 04:39 AM
I have a text file with configuration information gathered from my systems.
I need to search those files for any IP address and delete it or mask it. I might have different IP addresses in the same file. So I am looking for a pattern like xxx.xxx.xxx.xxx to delete or maske.
How can I do that?
thank you in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2006 04:41 AM
тАО08-25-2006 04:41 AM
Re: pattern search and replace
:$s/oldstring/newstring/g
which will replace oldstring to newstring globally in the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2006 04:50 AM
тАО08-25-2006 04:50 AM
Solutionsed -e '/dog/d' -e '/cat/d' -e 's/cow/Giraffe/g' < infile > outfile
This would read infile and delete every line that contains 'dog' or 'cat' and substitutes "Giraffe" for every instance of "cow" and write the result to outfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2006 04:56 AM
тАО08-25-2006 04:56 AM
Re: pattern search and replace
If you want to change an address pattern, you could use:
# perl -pe 's/\Q127.0.0.1/127.0.0.2/' file
...and if you wanted to delete lines containing it:
# perl -ne 'print unless m/\Q127.0.0.1/' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2006 04:57 AM
тАО08-25-2006 04:57 AM
Re: pattern search and replace
grep -e 120.340.056.078 -e 012.012.013.103 -e 020.030.040.050 -e 015.016.170.180 your_filename
Note that this assumes you want just certain addressess and that all addresses have the same format (ie ###.###.###.###) but if the addresses have leading zeros stripped (ie, 12 rather than 012), then you'll have to match exactly what is in the file.
To change a record that matches your search criteria, you'll need to use awk or a shell or Perl script.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2006 06:17 AM
тАО08-25-2006 06:17 AM
Re: pattern search and replace
perl -p -e 's/([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)//' file
if you wanted to delete them from the file completely.
perl -pi -e 's/([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)//' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2006 08:35 AM
тАО08-28-2006 08:35 AM
Re: pattern search and replace
I am new to scripting and perl.
How can I put the command you suggested in a shell script so I apply it on all the files in a directory? I am trying the following but it's not working but if I run your command on a specific file from the command line it works fine.
#!/usr/bin/sh
for FILE in `ls *.html`
do
{
perl -p -e 's/([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)//' $FILE > noip-$FILE;
}
done