Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

How to use bash script? Input vs output

I use bash script in which I modified definition of input and output:

###Original definition input vs. output:
    infile=$1
    outfile="${infile}.mlf"
    tmpfile="${infile}.tmp"
    tmpfile1="${infile}.tmp1"

for use in different folders, so script, input and output are in different folder:

###Modified definition input vs. output:
        mid=$1
        infile="/var/www/tmp/input/$mid.vtt"
        outfile="/var/www/tmp/output/$mid.mlf"
        tmpfile="{infile}.tmp"
        tmpfile1="${infile}.tmp1"

I want to run this script. It will be used to convert text files "$mid.vtt" (mid means multimedia id) from "input" folder to "$mid.mlf" to "output" folder. I modified as it is shown, but some error messages are shown:

"cat: /var/www/tmp/output/1.vtt.vtt: No such file or directory" "cat: /var/www/tmp/output/1.vtt.vtt.tmp1: No such file or directory" "rm: cannot remove `/var/www/tmp/output/1.vtt.vtt.tmp1': No such file or directory"

The whole bash script is below. I changed only definition of input vs. outputs.

###input vs. output
                mid=$1
                infile="/var/www/tmp/input/$mid.vtt"
                outfile="/var/www/tmp/output/$mid.mlf"
                tmpfile="${infile}.tmp"
                tmpfile1="${infile}.tmp1"
                i=1
                touch $tmpfile

            ###script
                cat $infile | grep -v 'WEBVTT' | grep -v "--" | grep -v '^$' | sed 's/?/./g' | sed 's/!/./g' | tr -d '.' | tr -d "," | tr -d ";" | tr -d ":" | awk '{ print tolower($0) }' > $tmpfile

                nlines=$(cat $tmpfile | wc -l)

                while [ $i -le $nlines ]
                do
                    line=$(cat $tmpfile | sed $i'q;d')
                    printf '%s
' $line | sed '/^s*$/d' >> $tmpfile1
                    i=$[$i+1]
                done

            ###export to output
                echo "#!MLF!#" > $outfile
                echo ""*/dummyfile.lab"" >> $outfile
                cat $tmpfile1 | awk '{if($0 !~ /*/) print "0 0 "$0; else print $0}' >> $outfile
                echo "." >> $outfile

            ###deleting tmp files
                rm $tmpfile
                rm $tmpfile1   

I dont'know where is a problem. I used chmod to set right permissions. Input file exists, folders exist..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Now it works fine.

mid=$1 infile="/home/var/www/vids/$mid/$mid.vtt" outfile="/var/www/tmp/vtt-to-mlf/${mid}.mlf" tmpfile="/var/www/tmp/vtt-to-mlf/${mid}.tmp" tmpfile1="/var/www/tmp/vtt-to-mlf/${mid}.tmp1"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...