I have a makefile with :
zvals: resize
zMin=$$(gdalinfo -mm ./crop_xl.tmp.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 1 | cut -d . -f 1);\
zMax=$$(gdalinfo -mm ./crop_xl.tmp.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 2 | cut -d . -f 1);\
echo Altidutes range: $$zMin $$zMax
python ../script/slice.py $$zMin $$zMax $(SLICES) > ./slices.tmp.txt
Last line fails because $$zMin and $$zMax in python ../script/slice.py $$zMin $$zMax $(SLICES) > ./slices.tmp.txt are empty and fail to provide any numbers to the python command.
Meanwhile, the exact same $$zMin and $$zMax in echo Altidutes range: $$zMin $$zMax properly prints Altidutes range: -
Hack
My "hack" is to inline it ALL via systematic ;\ at the end of each lines :
zvals: resize
zMin=$$(gdalinfo -mm ./crop_xl.tmp.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 1 | cut -d . -f 1);\
zMax=$$(gdalinfo -mm ./crop_xl.tmp.tif | sed -ne 's/.*Computed Min\/Max=//p'| tr -d ' ' | cut -d "," -f 2 | cut -d . -f 1);\
echo Altidutes range: $$zMin $$zMax;\
python ../script/slice.py $$zMin $$zMax $(SLICES) > ./slices.tmp.txt
Then $$zMin and $$zMax are defined in the python command, which therefor receives its needed values and it works.
Comment and question
This seems very ugly to me. How should I do to properly pass values to the last python command within my makefile ?
Related
I'm extracting two md5sums by using this code:
md5sum test{1,2} | cut -d' ' -f1-2
I'm receiving two md5sums as in example below:
02eace9cb4b99519b49d50b3e44ecebc
d8e8fca2dc0f896fd7cb4cb0031ba249
Afterwards I'm not sure how to compare them. I have tried using the xargs:
md5sum test{1,2} | cut -d' ' -f1-2 | xargs bash -c '$0 == $1'
However, it tries to execute md5sum as a command
Any advice?
Try using a command subsitution instead
#!/bin/bash
echo 1 > file_a
echo 2 > file_b
echo 1 > file_c
file1=file_a
# try doing "file2=file_b" as well
file2=file_c
if [[ $(sha1sum $file1 | cut -d ' ' -f1-2) = $(sha1sum $file2 | cut -d ' ' -f1-2) ]]; then
echo same
else
echo different
fi
I am checking to see if a file I am hoping to create conflicts with a file that has the same name.
FILEPATH=/root/logs/pData*.csv
COMPPATH=/root/logs/pData*.csv.gz
shopt -s nullglob
thisYear="$(date +"%Y")"
thisMonth="$(date +"%m")"
thisDay="$(date +"%d")"
thisTime="$(date | cut -d ' ' -f 4 | tr : _)"
for file in $FILEPATH
do
fileYear="$(stat -c %y $file | cut -d'-' -f 1)"
fileMonth="$(stat -c %y $file | cut -d'-' -f 2)"
fileDay="$(stat -c %y $file | cut -d'-' -f 3 | cut -d' ' -f 1)"
fileTime="$(stat -c %y $file | cut -d ' ' -f 2 | cut -d '.' -f 1 | tr : _)"
if (("$fileYear" < '1990'))
then
fName="pData_"$thisYear"_"$thisMonth"_"$thisDay"_"$thisTime".csv.gz"
else
fName="pData_"$fileYear"_"$fileMonth"_"$fileDay"_"$fileTime".csv.gz"
fi
echo $fName
for file in $COMPPATH
do
if ('/root/logs/'$fName == $file)
then
echo "OOPS"
fi
done
done
The script works as intended for the most part, printing OOPS when I run into a file of the same name, but for files that don't exist it prints
./compress.sh: line 31: /root/logs/pData_2015_09_18_22_25_44.csv.gz: No such file or directory
Why is this printed?
How do I prevent this from happening?
The string comparison is wrong. Using single parentheses is creating a sub-shell and trying to execute '/root/logs/'$fName
Set your string compare to be:
if [[ '/root/logs/'$fName = $file ]]
See: http://www.tldp.org/LDP/abs/html/comparison-ops.html
I use this BASH script to filter text from one text file to another. Text is encoded in UTF 8.
#!/bin/bash
mid=$1
infile="/var/www/tmp/textgrid_uploads/${mid}.txt"
outfile="/home/var/www/vids/$mid/${mid}_textgrid.mlf"
tmpfile="/home/var/www/vids/$mid/${mid}.tmp"
i=1
touch $tmpfile
cat $infile | grep "text =" | cut -d '"' -f2 | tr -d ',' | tr -d '.' | tr -d ':' | tr -d ';' | tr -d '!' | tr -d '?' > $tmpfile
#| awk '{ print tolower($0) }'
#cat $infile | grep -v "<" | egrep -v '^[[:space:]]*$' | tr -d '.' | tr -d "," | tr -d ";" | tr -d ":" | tr -d "^" | tr -d '#' | tr -d '?' | tr -d '!' | tr -d '%' | tr -d '#' | tr -d '*' | tr -d '~' | grep -v '((xxxxx))' | awk '{ print tolower($0) }' > $tmpfile
#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)
echo "#!MLF!#" >> $outfile
echo "\"*/dummyfile.lab\"" >> $outfile
while [ $i -le $nlines ]
do
line=$(cat $tmpfile | sed $i'q;d') #zobrazi konkretny riadok
printf '%s\n' $line | sed '/^\s*$/d' | cut -d "/" -f1 | egrep -v '^[[:space:]]*$' >> $outfile #zapis po riadkoch s odstranenim znaciek
i=$[$i+1] #pocitadlo
done
echo "." >> $outfile
rm $tmpfile
Output of this script is:
#!MLF!#
"*/dummyfile.lab"
<feff> V utorok o devätnástej bude vo fejs
I want to remove first word feff with both brackets. Please give me whole example how to do it. I am new in Bash and I just use this script I didn't create it. Thanks guys.
tar -x -v -z -f abc.tar.gz -C ~/libs/dl/ | cut -d '/' -f 1 | sort | uniq >> `dirname ~/libs/dl/`/.extracted_dirs
I don't know too much about scripts but I need a script that will run this command:
g++ -O0 -c fileName.cpp && nm fileName.o | egrep ' [A-Z] ' | egrep -v ' [UTV] ' | grep -v .eh > fileName.txt
for files with names 000000 - 008577. So how should my script be written?
UPD2:
I've written a script and it works:
#!/bin/bash
s1="g++ -O0 -c "
s2=".cpp && nm "
s3=".o | egrep ' [A-Z] ' | egrep -v ' [UTV] ' | grep -v .eh >> "
s4=".txt"
for ((i=0; i<=8577; i++)) do
num="$( printf '%06d' ${i})"
s="${s1}${num}${s2}${num}${s3}${num}${s4}"
eval $s
done
Try removing the spaces around the equal sign when you get to num and s.
I've written working code:
#!/bin/bash
s1="g++ -O0 -c "
s2=".cpp && nm "
s3=".o | egrep ' [A-Z] ' | egrep -v ' [UTV] ' | grep -v .eh >> "
s4=".txt"
for ((i=0; i<=8577; i++)) do
num="$( printf '%06d' ${i})"
s="${s1}${num}${s2}${num}${s3}${num}${s4}"
eval $s
done