How to write a batch command in linux ubuntu 10.04?
-
04-12-2019 - |
Domanda
I have an installed library called Gdal which runs certain GIS commands.
This command runs for a single file
gdal_translate -a_srs EPSG:25832 INPUT_FILE OUTPUT_FILE
but I would like to run a batch command which iterates through all *.tif files so I don´t have to write the name of each one (i´ve got 1300 files!)
I tried this in a .sh file...but it didn´t work
#!/bin/bash
for FILE in *.tif
do
BASE=$FILE .tif
NEWFILE=test/${BASE}.tif
gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done
could anyone show me how to do this?
yours,
Robert
Soluzione
$FILE includes the .tif
extension. Also BASE=$FILE .tif
doesn't do what you think (it executes .tif
with $BASE set to $FILE for the duration of the command).
You also have the difference between -a_srs
and -s_srs
. I don't know which you intended.
The end result is, I think, that you want to use test/$FILE
as the output filename.
#!/bin/bash
for FILE in *.tif; do
gdal_translate -s_srs EPSG:25832 "$FILE" "test/$FILE"
done
(The quotes make it work with a path with spaces in it. Putting the for
and do
on the same line is a common way of writing it to save space.)
Altri suggerimenti
Your FILE variable already has .tif on the end, so you are appending .tif again. Try this instead:
#!/bin/bash
for FILE in *.tif
do
NEWFILE=test/${FILE}
gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done