I want to delete these files:
-rw-r--r-- 1 mac mac 2459 Sep 16 10:54 multicol.aux
-rw-r--r-- 1 mac mac 8941 Sep 16 10:54 multicol.log
-rw-r--r-- 1 mac mac 40354 Sep 16 10:54 multicol.idx
-rw-r--r-- 1 mac mac 14311 Sep 16 10:54 multicol.glo
-rw-r--r-- 1 mac mac 151368 Sep 16 10:54 multicol.dvi
I first tried:
rm multicol.${dvi|log|idx|glo}
Then I tried:
rm multicol.${dvi|log|idx|glo}$
I can't remember it... I think I have seen how to do this?
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
rm multicol.{aux,dvi,glo,idx,log}
Ah, it was the comma that did the whole thing, thanks.
I have a new bash file substitution problem...
I have a Latex-directory and I want to replace all occurences of
"old_string" with "new_string" both inside the .tex-files and
"outside". So I guess I must do a:
1) find . -iname *.tex | xargs grep -i old_string | something (looks
*inside* .tex-files for old_string and replaces occurences inside)
2) find . -iname *.* | grep -i old_string | mv {} new_string (or
something, since old_string will also be part of some of the
filenames, like old_string.gif => new_string.gif)
I'm not really into awk and sed, but I'm sure somebody will post
something that uses those functions and then I'll see if I can learn
from that... There are probably many ways of doing it, but I can't find
one...
-snip-
> 1) find . -iname *.tex | xargs grep -i old_string | something (looks
> *inside* .tex-files for old_string and replaces occurences inside)
>
> 2) find . -iname *.* | grep -i old_string | mv {} new_string (or
> something, since old_string will also be part of some of the
> filenames, like old_string.gif => new_string.gif)
Is nobody willing to tell me how to replace old_string with new_string
into a directory like shown above? I could do part 2 manually...
find . -iname '*.tex' | xargs grep -li old_string |
while IFS= read -r file
do
sed 's/old_string/new_string/' > tempfile && mv tempfile "$file"
done
> *inside* .tex-files for old_string and replaces occurences inside)
Are there subdirectories? If not, you don't need find:
for file in *.[[Tt][Ee][Xx]]
do
sed 's/old_string/new_string/' > tempfile && mv tempfile "$file"
done
> 2) find . -iname *.* | grep -i old_string | mv {} new_string (or
> something, since old_string will also be part of some of the
> filenames, like old_string.gif => new_string.gif)
for file in *old_string*
do
left=${file%old_string*}
right=${file#*old_string*}
mv -i "$file" "${left}new_string$right"
done
> I'm not really into awk and sed, but I'm sure somebody will post
> something that uses those functions and then I'll see if I can learn
> from that... There are probably many ways of doing it, but I can't find
> one...
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
character lists within an extra set of brackets?
Is that a typo or a pattern matching syntax with which I'm unfamiliar?
That's a typo.
for file in *.[Tt][Ee][Xx]
> On 2006-09-16, Martin Jørgensen wrote:
>>
>> I have a new bash file substitution problem...
>>
>> I have a Latex-directory and I want to replace all occurences of
>> "old_string" with "new_string" both inside the .tex-files and
>> "outside". So I guess I must do a:
>>
>> 1) find . -iname *.tex | xargs grep -i old_string | something (looks
>
> find . -iname '*.tex' | xargs grep -li old_string |
> while IFS= read -r file
> do
> sed 's/old_string/new_string/' > tempfile && mv tempfile "$file"
> done
>
>> *inside* .tex-files for old_string and replaces occurences inside)
>
> Are there subdirectories? If not, you don't need find:
>
> for file in *.[[Tt][Ee][Xx]]
> do
> sed 's/old_string/new_string/' > tempfile && mv tempfile "$file"
> done
Thanks. Close enough for me to figure out a solution...
>> 2) find . -iname *.* | grep -i old_string | mv {} new_string (or
>> something, since old_string will also be part of some of the
>> filenames, like old_string.gif => new_string.gif)
>
> for file in *old_string*
> do
> left=${file%old_string*}
> right=${file#*old_string*}
> mv -i "$file" "${left}new_string$right"
> done
The same here... Thanks a lot...
> I have a Latex-directory and I want to replace all occurences of
> "old_string" with "new_string" both inside the .tex-files and
> "outside". So I guess I must do a:
>
> 1) find . -iname *.tex | xargs grep -i old_string | something (looks
> *inside* .tex-files for old_string and replaces occurences inside)
#v+
find . -iname '*.tex' -print0 |\
xargs -0 sed -ie 's/old_string/new_string/g' --
#v-
providing that your find supports -iname and -print0, your xargs
supports -0 and your sed supports -i; or:
#v+
find . -name '*.[Tt][Ee][Xx]' -exec \
sed -ie 's/old_string/new_string/g' -- {} \;
#v-
providing that your sed supports -i; or:
#v+
find . -name '*.[Tt][Ee][Xx]' -exec \
perl -pie 's/old_string/new_string/g' -- {} \;
#v-
providing you have perl; or:
#v+
find . -name '*.[Tt][Ee][Xx]' -exec sh foo.sh {} \;
#v-
where foo.sh has the following content:
#v+
sed 's/old_string/new_string/g' <"$1" >tmp && mv -- tmp "$1"
#v-
> 2) find . -iname *.* | grep -i old_string | mv {} new_string (or
> something, since old_string will also be part of some of the
> filenames, like old_string.gif => new_string.gif)
#v+
find . -name '*old_string*' -print0 |\
xargs -0 rename old_string new_string
#v-
providing that your find supports -print0, your xargs supports -0 and
you have rename; or:
#v+
find . -name '*old_string*' -exec rename old_string new_string {} \;
#v-
providing that you have rename.
If you don't have rename you can change the command 'rename' with
'bash bar.sh' providing you have bash and bar.sh has the following
content:
#v+
FROM="$1"
TO="F2"
shift 2
for FILE; do
F="${FILE/$FROM/$TO}"
[ X"$F" = X"$FILE" ] || mv -- "$FILE" "$F"
done
#v-
or with 'sh bar.sh' providing bar.sh has following content:
#v+
FROM="$1"
TO="F2"
shift 2
for FILE; do
PRE="${FILE%%$FROM*}"
if [ X"$PRE" = X"$FILE" ]; then continue; fi
POST="${FILE#*$FROM}"
mv -- "$FILE" "$PRE$TO$POST"
done
#v-
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
perl -i -pe 's/old_string/new_string/g' *.tex
> 2) find . -iname *.* | grep -i old_string | mv {} new_string (or
> something, since old_string will also be part of some of the
> filenames, like old_string.gif => new_string.gif)
for f in *${old_string}*; do
prefix="${f%%${old_string}*}"
suffix="${f##*$old_string}"
mv "$f" "${prefix}${new_string}$suffix"
done
--
Glenn Jackman
Ulterior Designer
Hi, thanks for the extra educative contributions, all of you. I'll study
them later and see what I can learn from them and keep subscribing
here...