![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find and replace | javeed7 | Shell Programming and Scripting | 1 | 04-02-2008 09:00 AM |
| find and replace | mahabunta | UNIX for Dummies Questions & Answers | 7 | 09-21-2006 12:05 PM |
| find and replace | valhutch | UNIX for Dummies Questions & Answers | 4 | 07-29-2006 05:20 PM |
| find and replace | vikas_j@hotmail | UNIX for Dummies Questions & Answers | 3 | 02-25-2002 05:41 PM |
| Find & Replace | gagansharma | Shell Programming and Scripting | 3 | 11-27-2001 04:17 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find and Replace
After running a command like
grep -ir files2/ * This will find all the files that contain "files2/" in it. For example if it finds files2/dir/today files2/dir/yesterday files2/dir/2daysago Now it may find 100 instances, so is there a quick find and replace command I can use? I basically want to remove "files2" from all instances. tia. |
|
||||
|
If you want to remove "files2/" from the file itself, vi the file and type below and enter
:%s/^files2\///g If you want to repalce from grep output # grep files2 filename | sed 's/files2\///' This all will give u output dir/today dir/yesterday dir/2daysago |
|
||||
|
Ok, maybe I should describe what I want to do more clearly.
On a windows server where we ftp files to, we have unix scripts that move files to certain directories on the windows server that begin with "data2/". That has changed, they are removing "data2/" from the path, not to mention different servers but thats not my question. I have about 30 production unix scripts to modify in a certain unix directory that contain "data2/" instances. I cant rename the scripts, I basically have to remove the "data2"/ from each one. Is there a command I can run from the prompt, or do I have to do each one with VI. Either way you guys advise to be easier, how do you do it? ![]() |
|
|||||
|
Quote:
Code:
grep -ir files2/ * > list.txt while read file do sed -i -e "s/files2\///g" $file done < list.txt |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|