The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a string inside files yoavbe Shell Programming and Scripting 12 05-05-2008 01:19 PM
MV files with xargs or -exec malaymaru Shell Programming and Scripting 4 04-28-2008 10:40 AM
joining command results, and substitution ncatdesigner Shell Programming and Scripting 6 04-17-2008 11:37 AM
Difference between xargs and exec vibhor_agarwali UNIX for Dummies Questions & Answers 19 06-09-2005 07:54 AM
find | xargs cat asal_email Shell Programming and Scripting 4 03-17-2005 12:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-17-2008
myndcraft myndcraft is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
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"
I get back these results.

.//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?
  #2 (permalink)  
Old 05-17-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
find . -name '*.tif' |
sed -e 's%\(.//*\)\(.\)\(.\)\(.\)\(.*\)%ditto \1\2\3\4\5 /some/path/\2/\3/\4/%'
| sh
It's a thin line between a one-liner and an "actual script".

Last edited by era; 05-17-2008 at 08:56 AM.. Reason: Optionally allow more than one slash
  #3 (permalink)  
Old 05-17-2008
myndcraft myndcraft is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
Thanks era, works great! Time to spend some time with the sed docs though... I knew it could do it, but admittedly I'm not very familiar with it
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0