login | register | profile | members | admin

jboard > UNIX / Linux > bashscripte page 1 all
07.05.07 22:22 bashscripte, Post #1
jens
moin,

da ich meine bashkentnisse noch ein wenig aufwerten wollte und weil ich eben zufaellig mal nen kleines script gebaut habe, habe ich mir gedacht, dass soein thread evtl. ganz praktisch waere...

Also poste ich hier einfach mal mein script, welches uebrigends den string "bla" in allen dateien eines Verzeichnisses in "blubb" umwandelt
CODE:

!# /bin/bash

ls > data.txt

for data in $(cat data.txt); do
sed $data -e s/bla/blubb/g > $data.neu;
done

rm data.txt

rm data.txt.neu

for data in *.neu; do
base=`basename $data .neu`
mv $data $base
done


PS: ihr werdet sicherlich eine sinnvollere Anwendung finden

Lache und die Welt lacht mit dir, weine und du weinst allein. -oldboy
edit quote delete close
27.04.07 15:28 bashscripte, Post #2
WitzTuete
Dinge die die Welt nicht braucht :>

Teamwork is essential - it allows you to blame someone else.
edit quote delete close
27.04.07 15:56 bashscripte, Post #3
jens
Wenn du deine These auch mit einem Argument untermauern koenntest, muesste ich das jetzt nicht als spam abtun!

Du kannst aber gerne mal aufm server mit 90% load noch ne GUI laufen lassen und in 1000 textdateien einzeln nen string mehrmals ersetzen, falls das fuer dich einfacher sein sollte.

Lache und die Welt lacht mit dir, weine und du weinst allein. -oldboy
edit quote delete close
07.05.07 22:14 bashscripte, Post #4
Joshua
CODE:

#!/bin/bash

#dir with artist dirs ... put your dirs here
BASEDIR="/media/usbdisk/mp3s"
OUTDIR="/media/usbdisk/mp3s_indexed"

#create output dir if not exists
if [ ! -d $OUTDIR ]
then
mkdir -p $OUTDIR
fi

#string manipulation functions
toLower()
{
echo "$1" | tr "[:upper:]" "[:lower:]"
}

noDigits()
{
echo "$1" | tr -d "[:digit:]"
}

noSpaces()
{
echo "$1" | tr -d " "
}

#parameter $1: space separated string with artists initials
#e.g.: "A B C" (only upper case, these will also work vor lower case initials)
#create dir in outdir with softlinks to the artists dirs beginning with the chars in $1
makeindexdir()
{
CHARS="$1"
nd=$(noDigits "$CHARS")
lc=$(toLower "$nd")
allchars="$CHARS $lc"
curod=$(noSpaces "$CHARS")
curoutdir="$OUTDIR/$curod/"

if [ ! -d $curoutdir ]
then
mkdir -p $curoutdir
fi

for a in $allchars
do
CURDIRS=$BASEDIR/$a*

for d in $CURDIRS
do
if [ -d "$d" ]
then
ln -sf "$d" "$curoutdir"
fi
done
done
}

#create softlinks
makeindexdir "0 1 2 3 4 5 6 7 8 9 A B"
makeindexdir "C D E"
makeindexdir "F G H"
makeindexdir "I J K"
makeindexdir "L M N"
makeindexdir "O P Q R"
makeindexdir "S T"
makeindexdir "U V W X Y Z"



_________________
edit:
@jens: du brauchst auf jeden fall ne
CODE:
-formatierung im forum ... echt fies so ohne tabs
edit2: isses normal dass ein " D (ohne leerzeichen dazwischen) zu nem smiley verwandelt wird?


edit quote delete close

log in before posting!
login