[rescue] [OT} shell help

Stéphane Tsacas stephane.tsacas at gmail.com
Sun Apr 4 07:47:29 CDT 2010


On Sun, Apr 4, 2010 at 07:17, Sridhar Ayengar <ploopster at gmail.com> wrote:

> Marcin 'Rambo' Roguski wrote:
>
>> ./Airbus A320-200/CS-TKJ, SATA Internacional 2.jpg ->
>>> ./Airlines/SATA Internacional/Airbus A320-200, CS-TKJ 1.jpg
>>>
>>
>> typo, should be:
>>
>> ./Airlines/SATA Internacional/Airbus A320-200, CS-TKJ 2.jpg
>>
>
> Yeah, I'd use awk for this.  Would be simpler than sed.
>
> Peace...  Sridhar
>
>
Exactly, an awk script which prints out the commands you want to execute,
like
ln -s "./Airbus A320-200/CS-TKJ, SATA Internacional 2.jpg" "./Airlines/SATA
Internacional/Airbus A320-200, CS-TKJ 1.jpg"
...

and you test it first by doing
ls | awk ...
and see if what it prints is OK. If it is, you just add | sh -x at the end.
Here is a simple example :

$ ls -l
total 0
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 bar
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 foo
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:26 foo bar
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 quux
$
$ ls | awk '{ printf ("cp \"" $0 "\" \"" $0 ".orig\"\n"); }'
cp "bar" "bar.orig"
cp "foo" "foo.orig"
cp "foo bar" "foo bar.orig"
cp "quux" "quux.orig"
$
$ ls | awk '{ printf ("cp \"" $0 "\" \"" $0 ".orig\"\n"); }' | sh -x
+ cp bar bar.orig
+ cp foo foo.orig
+ cp 'foo bar' 'foo bar.orig'
+ cp quux quux.orig
$
$ ls -l
total 0
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 bar
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:41 bar.orig
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 foo
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:26 foo bar
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:41 foo bar.orig
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:41 foo.orig
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:22 quux
-rw-r--r-- 1 slt Aucun 0 Apr  4 14:41 quux.orig

Don't forget the quotes around file names ! ! Files can contain spaces
and/or other nasty characters !!


-- 
Stephane
http://updatedoften.blogspot.com



More information about the rescue mailing list