Monday, April 10, 2017

Bash - Scripting - part 1- replace part of string

#!/bin/bash
#
# Change file extensions
#
FILES=/homeb/d54712/sandbox/scripts/data.d/files.txt
exec 3< $FILES
exec <&3
while read file
do
        echo "${file/%.pcx/.jpg}"
done

Results:


# cat files.txt
132014.pcx
132023.pcx
132024.pcx
132025.xml
132026.pcx
132026.pcx
132027.xpm
132027.pcx
132027.xml
132028.pdf
132028.pcx
132029.pcx
132029.pcx
132029.pdf
132030.pcx
132030.pcx
132030.pcx
132030.pcx
132031.gif
132031.pcx
132031.pcx

# Convert .pcx to .jpg

./file_convert.sh
132014.jpg
132023.jpg
132024.jpg

132025.xml
132026.jpg
132026.jpg

132027.xpm
132027.jpg
132027.xml
132028.pdf
132028.jpg
132029.jpg
132029.jpg

132029.pdf
132030.jpg
132030.jpg
132030.jpg
132030.jpg

132031.gif
132031.jpg
132031.jpg

No comments:

Post a Comment