passing variables to sed
Is there a way to pass variables to sed? I would like to present a user with a list with line numbers, then prompt the user for the line number that they would like to delete. I thought that I would like to use sed to delete that line, here is what I had in mind:
cat list | more echo "Enter line number to be deleted..." read myNum sed -e $myNumd I know that I can do this to delete line 5 sed -e 5d but I am having trouble passing variables. Any ideas? Or other solutions? JJ |
Something like
Code:
#!/bin/bash Cheers, Tink |
Tinkster,
Perfect, thank you very much it worked great! JJ |
Code:
[ddipaolo@quinn ~]% echo -e "1\n2\n3\n4\n" > temp.txt |
But your solution doesn't write back to
the same file ;) Cheers, Tink |
So redirect it to the file ...
|
Well done :)
Results in an empty file ... Cheers, Tink |
Quote:
Code:
cat temp.txt | sed -e `echo $LINENUM`d > temp.txt |
Quote:
Cheers, Tink |
All times are GMT -5. The time now is 07:56 PM. |