This is currently deleting the whole contents of the file in question:

cat $dir | grep -v "Listen $rpc_port" > $dir

The file contents:

Listen 9200
Listen 9201
Listen 9202
Listen 9203
Listen 9204

Could someone please either fix this or give me a working alternative?

  • 2
    The pipe from cat to grep is a bit useless here, as you could have done grep pattern $dir – Bernhard Aug 6 '12 at 6:17

You cannot write (=redirect) to the same file you are reading from. Either redirect to a different file, or use sed.

sed -i "/$rpc_port/d" $dir
|improve this answer|||||
  • ah, I see :P tyvm for your help, that works great :D – Mr. King Aug 6 '12 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.