Zeichen in Variaable ersetzen.

H

heckmic

Mitglied
Ich habe ein Script geschrieben, welches Dateien, die ich mit dem vdr aufgenommen habe in dvd konforme mpegs wandelt. Nun habe ich ein Problem mt der ausgabedatei.

Die Variable heißt $VDRFILE und der Inhalt ist z.B:

/mnt/ftp/tv/Verliebt_in_Berlin/_/2006-08-23.19.05.99.99.rec/001.vdr

das ist auch so ok, nun möche ich aber eine Variable haben ($VDROUT) die als Inhalt das hier hat:

/mnt/ftp/tv/Verliebt_in_Berlin/_/2006-08-23.19.05.99.99.rec/001.mpg

also die letzten 3 Zeichen des Strings dur "mpg" ersetzen.
Wie kann ich das machen?

Hier das Script:

#!/bin/sh
date >> /mnt/ftp/tv/convert.log
/etc/init.d/vdr stop
/etc/init.d/vdradmin-am stop
VDRFILE=`find /mnt/ftp/tv -mtime +1 | grep 00..vdr -m 1`
VDROUT=$VDRFILE
nice -20 tovid -in "$VDRFILE" -out "$VDROUT" -pal -half-dvd
echo "VDR Datei bearbeitet $VDRFILE" >> /mnt/ftp/tv/convert.log
rm "$VDRFILE"
echo "QUELLDATEI $VDRFILE geloescht" >> /mnt/ftp/tv/convert.log
date >> /mnt/ftp/tv/convert.log
/etc/init.d/vdr start
/etc/init.d/vdradmin-am start
 
Zuletzt bearbeitet:
Hallo,

Code:
VDROUT=`echo ${VDRFILE} | sed s/\.vdr$/\.mpg/`

Versuchs mal damit.

Gruß
 
Oder, nur mit bash-Mitteln

Code:
VDROUT=${VDRFILE%vdr}mpg

Gruss Xanti
 
@Xanti,

stimmt :)
Da spart man sogar noch einen Prozess

Gruß
 
Ihr seid echt spitze, danke!

Kann mir einer noch erklären, was diese Zeichen alle bedeuten?
 
man bash:

Code:
       ${parameter%word}
       ${parameter%%word}
              The  word  is  expanded to produce a pattern just as in pathname
              expansion.  If the pattern matches a  trailing  portion  of  the
              expanded value of parameter, then the result of the expansion is
              the expanded value of parameter with the shortest matching  pat-
              tern  (the  ``%''  case)  or  the  longest matching pattern (the
              ``%%'' case) deleted.  If parameter  is  @  or  *,  the  pattern
              removal  operation  is  applied  to each positional parameter in
              turn, and the expansion is the resultant list.  If parameter  is
              an  array  variable subscripted with @ or *, the pattern removal
              operation is applied to each member of the array  in  turn,  and
              the expansion is the resultant list.

Gruss, Xanti
 
Die bash kennt auch noch sowas:
Code:
VDROUT=${VDRFILE/\.vdr/.mpg}
;)


Gruß Wolfgang
 

Ähnliche Themen

Open-Xchange auf OpenSuse mit Commu. Installer - Compiler Fehler

Zurück
Oben