![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to find a string inside files | yoavbe | Shell Programming and Scripting | 12 | 05-05-2008 10:19 AM |
| MV files with xargs or -exec | malaymaru | Shell Programming and Scripting | 4 | 04-28-2008 07:40 AM |
| joining command results, and substitution | ncatdesigner | Shell Programming and Scripting | 6 | 04-17-2008 08:37 AM |
| Difference between xargs and exec | vibhor_agarwali | UNIX for Dummies Questions & Answers | 19 | 06-09-2005 04:54 AM |
| find | xargs cat | asal_email | Shell Programming and Scripting | 4 | 03-16-2005 08:16 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
String substitution on find results inside exec/xargs
What I'm trying to do is perform a copy, well a ditto actually, on the results of a find command, but some inline string substitution needs to happen.
So if I run this code Code:
find ./ -name "*.tif" .//1234567.tif .//abcdefg.tif Now the action from exec or xargs I want would be these two things.... ditto .//1234567.tif /some/path/1/2/3/ ditto .//abcdefg.tif /some/path/a/b/c/ So as you can see it's taking the first three characters from each found result and using those to construct a path. Any ideas I'm sure this can be done easier in a actual script, but i need to keep this as an actual "one line" command. Any ideas? |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
find . -name '*.tif' | sed -e 's%\(.//*\)\(.\)\(.\)\(.\)\(.*\)%ditto \1\2\3\4\5 /some/path/\2/\3/\4/%' | sh Last edited by era; 05-17-2008 at 05:56 AM. Reason: Optionally allow more than one slash |
| Thread Tools | |
| Display Modes | |
|
|