Issue
I have 2 lines of sed that I have trouble understanding
I understand that the syntax of sed is :
sed OPTIONS [SCRIPT] [INPUTFILE]
but in this command below there is no input file I am just curious what this is doing, any help is very much appreciated
1.
$(echo $d | sed 's/.*\///g')#
cat /kaldi/README | sed "s/akiplaner/${n}/g" > extracted/$nf/etc/README #
*note : below is the whole code
for d in /dir1/dataset/audios/*; do
echo $d
n=$(echo $d | sed 's/.*\///g') #
nf=${n}
echo $n $a $nf
mkdir -p extracted/$nf/wav
mkdir -p extracted/$nf/etc
rm -f extracted/$nf/etc/prompts-original
rm -f extracted/$nf/etc/PROMPTS
cat /kaldi/README | sed "s/akiplaner/${n}/g" >extracted/$nf/etc/README #
for f in $d/*.wav; do
n2=$(echo $f | sed 's/.*\///g')
n3=$(echo $n2 | sed 's/\.wav//g') # removing .wav from $n2 string
echo $n2
echo $n3
cp $f extracted/$nf/wav/$n2
#sox --vol 0.01 $f -t wav extracted/$nf/wav/$n2;
normalize-audio -a 0.3 extracted/$nf/wav/$n2
cp $d/$n3.txt temp.txt
echo "$n3 $(cat temp.txt)" >>extracted/$nf/etc/prompts-original
echo "${nf}/mfc/${n3} $(cat temp.txt)" >>extracted/$nf/etc/PROMPTS
done
a=$(($a + 1))
done
Solution
there is no input file I am just curious what this is doing
The answer is at your fingertips.
$ LC_ALL=C sed --help
...
... if no input files are
specified, then the standard input is read.
Note: |
shell operator connects one command standard output to another command's standard input. There are surely endless resources on the internet for basic introduction to shell streams and input output operations - it might be a good occasion to research some of them, like https://mywiki.wooledge.org/BashGuide/InputAndOutput .
sed OPTIONS [SCRIPT] [INPUTFILE]
It's:
$ LC_ALL=C sed --help
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
The stuff in [...]
is optional. ...
represents stuff it can be repeated.
There are man problems with the script - it will break on filenames with spaces or newlines in the name or on filenames with *
in the name... Remember to check your scripts with shellcheck - it will catch such mistakes.
's/.*///g' am I correct in saying this pattern is removing any file or folder whose name starts with
From a line of text it removes everything .*
before a /
slash. You can learn regex with fun with https://regexcrossword.com/ and sed here https://www.grymoire.com/Unix/Sed.html .
It's an odd way of writing basename "$n"
and the next line is just basename "$n" .wav
.
Answered By - KamilCuk Answer Checked By - Timothy Miller (WPSolving Admin)