-1

I want to use sed command in a loop passing a variable say a such that it searches for a and in the line it gets a it replaces "true" to "false".

I have a text file containing 3000 different names and another xml file containing 15000 lines. in the lines in which these 3000 entries are there i need to make changes.

I have written a code snippet but that is not giving expected output. Can anyone help. Thanks in advance.

for i in {1..3000}; do
    a=`awk NR==$i'{print $1}' names.txt`
    # echo $a
    sed -e '/$\a/ s/true/false/' abc.xml > abc_new.xml
done
JNYRanger
  • 6,829
  • 12
  • 53
  • 81
akansha shah
  • 11
  • 1
  • 3
  • Please do not add a comment on your question or on an answer to say "Thank you" If the answer had worked for you/and you beleive its the best solution, please *accept the answer* : http://stackoverflow.com/help/someone-answers – VDR Aug 21 '15 at 12:03

1 Answers1

1

You have to replace single-quotes(') around sed's parameters with double-quotes("). In bash, single-quote won't allow variable expansion. Also, you might want to use sed's in-place edit (pass -i option) in your for loop.

So the one liner script will look like:

for a in `cat names.txt`; do sed -i.bak -e "/$a/s/true/false/" abc.xml ; done
chicks
  • 2,393
  • 3
  • 24
  • 40
VDR
  • 2,663
  • 1
  • 17
  • 13