I\'m trying to remove a specific line from a file and then append the edited line to the file. I get last part right but my sed command to remove the old line is not working. >
i did try that and found that the variable value wasnt properly replaced by the shell in the sed statement . so the sed command instead of searching for the value as the pattern was doing a search with the variable name as pattern
ie it was trying to search $userinput as pattern @ EOL
this was due to the presence of single quotes , try your command again but replace them with double quotes : it worked im my sys.
code ::
Nitin@Kaizen ~> cat new
#!/bin/bash
echo "the input file :"
cat INPUT2.txt ;
echo "enter line to remove" ;
read rem ;
date >> sed.log ;
sed "/$rem/d" INPUT2.txt >> sed.log;
echo "the output file :" ;
cat sed.log;
run ::
Nitin@Kaizen ~ > ./new
the input file :
aa1
chap1
mk.t
temp.txt
z1
z2
enter line to remove
temp.txt
the output file :
Thu Mar 28 08:18:07 IST 2013
aa1
chap1
mk.t
z1
z2