- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Will "sed" do what I need?
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
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
тАО02-18-2008 09:27 AM
тАО02-18-2008 09:27 AM
I'm writing a script which creates a file containing a list of files with their paths. What I now need my script to do is create another file which will add "cp" before the path/filename and then add "path" at the end of each line within the first file. I think "sed" might do what I need but its been so long since I've used this command I've forgotten how. Any ideas anyone please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2008 09:35 AM
тАО02-18-2008 09:35 AM
Re: Will "sed" do what I need?
{ print "cp", $0, "path" }
I think.
Pete
Pete
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2008 09:53 AM
тАО02-18-2008 09:53 AM
Re: Will "sed" do what I need?
Assuming your file YourInputFile contains one absolute path to a file per line you could do like this and obtain what you want in YourOutputFile :
sed 's/^/cp /' < YourInputFile | sed 's/$/ path/' > YourOutputFile
Regards
Eric
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2008 09:58 AM
тАО02-18-2008 09:58 AM
Re: Will "sed" do what I need?
I would think by saying "then add 'path' at the end..." you may mean add the DIRECTORY path in which the file was found. Thus, '/usr/bin/echo' yields '/usr/bin'. If so, you could process with:
#!/usr/bin/sh
while read LINE
do
MYPATH=$(dirname $LINE)
echo cp ${LINE} ${MYPATH}
done < file.in > file.out
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2008 10:21 AM
тАО02-18-2008 10:21 AM
Re: Will "sed" do what I need?
Duh, I think you mean:
# sed -e 's!\(.*\)!cp \1 /newpath!' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-18-2008 03:13 PM
тАО02-18-2008 03:13 PM
Re: Will "sed" do what I need?
You can optimize this to one sed with two scripts:
sed -e 's/^/cp /' -e 's:$: path:' YourInputFile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2008 02:27 AM
тАО02-19-2008 02:27 AM
Re: Will "sed" do what I need?
sed -e '/^$/d' -e 's!\(.*\)!host cp \1 /stage/dst/backup!' /tmp/dst.bkfiles > /tmp/dst_bkfiles.sql
I now get output into a new file showing something like the following:
host cp /redo1/dst/redo05a.log /stage/dst/backup
host cp /redo2/dst/redo05b.log /stage/dst/backup
This does leave me with lots of blank spaces between the first and second path, but that shouldn't stop the script from running. Will find out tonight when I try it on a live system. If anyone knows how to remove numerous blank spaces between the two paths though, I'd be glad to hear from you.
Many thanks to you all again though for reminding me how to use SED!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2008 02:41 AM
тАО02-19-2008 02:41 AM
SolutionI dont see those lots of blanks spaces, unless you have them in the input file
Anyway you can add this filter :
-e 's! *! !g' ==> be aware that there are 2 space characters : it means one space followed by any number of spaces.
Your command will become :
sed -e '/^$/d' -e 's!\(.*\)!host cp \1 /stage/dst/backup!' -e 's! *! !g' /tmp/dst.bkfiles > /tmp/dst_bkfiles.sql
Regards
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2008 02:47 AM
тАО02-19-2008 02:47 AM
Re: Will "sed" do what I need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2008 02:52 AM
тАО02-19-2008 02:52 AM
Re: Will "sed" do what I need?
Many thanks everyone!