[Sussex] Bash string substitution
Ronan Chilvers
ronan at thelittledot.com
Fri Sep 30 12:57:49 UTC 2005
Sorry to reply to my own post but just cracked it:
for FIL in "Catalogue labels Size "$1/.*; do
PAT="s/A/BC/g"
NEW=$(basename "$FIL" | sed "$PAT")
echo $NEW
done
I was using single rather than double quotes on my sed expression which
is where the problem lay...
Cheers
Ronan
On Fri, 30 Sep 2005 13:47:07 +0100
Ronan Chilvers <ronan at thelittledot.com> wrote:
> For all you Bashers out there, what's a quick way to substitute 1
> character with 2 in a given string. I have a list of filenames I want
> to rename via a script, eg:
>
> A-012345.txt
>
> becomes
>
> BC-012345.txt
>
> or
>
> 2-A-789.txt
>
> becomes
>
> 2-BC-789.txt
>
> Using tr doesn't work because it only substitutes 1 for 1 (ie: A
> becomes B not BC).
>
> Any ideas?
>
> Ronan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050930/aa033af2/attachment.pgp
More information about the Sussex
mailing list