'Sed command not working based on variable
I am having problems in execution a sepefic sed command.
I have a bunch of files which will be target to several "find and replace" via sed.
In the file_test there is the following text example:
*FILENAME TESTE "DIR1.PGM1";*
My desired output is:
*FILENAME TESTE "/NEW_ROOT/DIR1.PGM1";*
The following command works:
*sed -i -e '/FILENAME/s!"!"/NEW_ROOT/!' file_test*
However having several alterations to make I opted to list the on a file a loop through it. list_changes FILENAME /NEW_ROOT/
Below its the logic I've implemented:
*#!/bin/bash
diretoria=pasta_b
ficheiro=teste
arquivo_2="$2" # serve para guardar o nome do txt
while read -r linha; do
grep_input=$(echo "$linha" | cut -d " " -f 1) #get input for sed
grep_output=$(echo "$linha" | cut -d " " -f 2) #get output for sed
cd ~/Desktop/FUENTES/"$diretoria"
novo_fich="novo_$ficheiro" #rename file
cat "$ficheiro" >> "$novo_fich".txt #rename file
comand_sed="sed -i -e '/"$grep_input'/s!"!"/'$grep_output"/!' "$novo_fich".txt"
echo "Comando : $comand_sed"
call_comand=$(${comand_sed})
cd ~/Desktop/FUENTES/
done < "$arquivo_2"*
The error it gives is the following:
sed: -e expression #1, char 1: unknown command: `''
However the command_sed variable outputs to a well constructed sed command:
sed -i -e '/LIBNAME/s!"!"/2sasdata2/!' novo_base08.txt
To sum up, my issue is giving a command based on a previously assigned variable (comand_sed)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
