Pessoalmente, eu evitaria codificar os nomes dos arquivos. Isso raramente é uma boa ideia e geralmente é melhor ter a opção de passar arquivos de destino como argumentos. Além disso, você está modificando o arquivo e excluindo o original. Isso não é eficiente, apenas modifique o arquivo na hora e imprima a sétima coluna sem precisar gravá-la no disco. Por exemplo:
#!/usr/bin/env bash
## Iterate over the file names given
for file in "$@"; do
## Get the output file's name. The ${file%.*} is
## the file's anme without its extension.
outfile="${file%.*}"_S.txt
## If the file exists
if [ -e "$file" ]; then
## remove the spaces and print the 7th column
sed 's/- /-/g' "$file" | awk '{print $7}' > "$outfile" &&
## Delete the original but only if the step
## above was successful (that's what the && does)/
rm "$file"
else
## If the file doesn't exist, print an error message
echo "The file $file does not exist!"
fi
done
Depois, você pode executar o script assim:
foo.sh /tmp/1wall_long.txt /tmp/1wall_test1.txt /tmp/1wall_test2.txt /tmp/1wall_test3.txt /tmp/20mt_OpenSpace_test1.txt /tmp/20mt_OpenSpace_test2.txt /tmp/20mt_OpenSpace_test3.txt /tmp/3mt_long.txt /tmp/3mt_OpenSpace_test1.txt /tmp/3mt_OpenSpace_test2.txt /tmp/3mt_OpenSpace_test3.txt /tmp/3rooms_test1.txt /tmp/3rooms_test2.txt /tmp/3rooms_test3.txt
Se você quiser ter os nomes codificados, apenas use uma matriz como sugerido por @choroba:
#!/usr/bin/env bash
files=(/tmp/1wall_long.txt /tmp/1wall_test1.txt /tmp/1wall_test2.txt /tmp/1wall_test3.txt /tmp/20mt_OpenSpace_test1.txt /tmp/20mt_OpenSpace_test2.txt /tmp/20mt_OpenSpace_test3.txt /tmp/3mt_long.txt /tmp/3mt_OpenSpace_test1.txt /tmp/3mt_OpenSpace_test2.txt /tmp/3mt_OpenSpace_test3.txt /tmp/3rooms_test1.txt /tmp/3rooms_test2.txt /tmp/3rooms_test3.txt )
## Iterate over the file names given
for file in "${files[@]}"; do
## Get the output file's name. The ${file%.*} is
## the file's anme without its extension.
outfile="${file%.*}"_S.txt
## If the file exists
if [ -e "$file" ]; then
## remove the spaces and print the 7th column
sed 's/- /-/g' "$file" | awk '{print $7}' > "$outfile" &&
## Delete the original but only if the step
## above was successful (that's what the && does)/
rm "$file"
else
## If the file doesn't exist, print an error message
echo "The file $file does not exist!"
fi
done