- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Replace one single line in files with equal filena...
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
11-23-2004 01:32 AM
11-23-2004 01:32 AM
Replace one single line in files with equal filename
Could someone help me with that?
I want to find files (all with the same filename) in a file hierarchy (tree structure). Some files have one equal line that I want to replace by an other line. Problem is, the files are in different directories and subdirectories. So "find" and "grep" alone are not enough, I have to know about the whole pathname.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2004 01:45 AM
11-23-2004 01:45 AM
Re: Replace one single line in files with equal filename
$ find /home -name plrtest
$ /home/plr/plrtest
So you use find to identify the files then use -exec or xargs to invoke sed to change the line! Or am I missing something?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2004 01:47 AM
11-23-2004 01:47 AM
Re: Replace one single line in files with equal filename
find /mypath -type f -exec grep -l pattern {} \;
will give you a list of all files in /mypath containing the string "pattern". You can send its output into sed like this :
find /mypath -type f -exec grep -l pattern {} \; | while read filename
do
cp ${filename} ${filename}.orig
sed "s/pattern/replacement/g" ${filemane}.orig > ${filename}
done
This will replace "pattern" by "replacement" in all files under /mypath. It will also left a .orig file for each file.
Regards,
Fred
"Reality is just a point of view." (P. K. D.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2004 01:48 AM
11-23-2004 01:48 AM
Re: Replace one single line in files with equal filename
how about:
find /topdir -name filename -exec grep -l equal_line {} \;
"grep -l" will show the filenames you need.
regards,
Thierry Poels.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2004 01:50 AM
11-23-2004 01:50 AM
Re: Replace one single line in files with equal filename
find
Redirect output into a file to obtain list (with full path) for these files.
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2004 02:42 AM
11-23-2004 02:42 AM
Re: Replace one single line in files with equal filename
while read fname
do
ed -s ${fname} <