How would i delete a line at specific line number
Hi guys ,
I m writing a script to delete a line at particular location. But i m unable to use variable for specifying line number. for example. Code:
sed -n '7!p' filename but Code:
sed -n '$variable!p' filename Code:
sed: -e expression #1, char 3: extra characters after command |
This would have to be covered in the sed one-liners.
Instead of not printing try deleing the line in question Code:
sed "${variable}d" filename |
Also, if you are using a variable, the SED command string needs to be in double-quotes.
|
Thanks for your input . But now i would like to enter a line at specific line number .
How would i establish this using sed. |
Have you met the man command or perhaps some of its friends on the web called search engines??
Sorry to be harsh but you have been given a solution which should guide you to what you require just that different options, ie not 'd' for delete, would need to be used. Remember that the community exists to educate, not to do the work for you. |
Well, now that you've solved the issue about specifying a variable address (using double quotes), you can test with other sed commands as well. For example:
Code:
sed "${variable}a newline to append" filename |
Hi,
Another good reference would be 'Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook'. :hattip: The above link and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! |
Code:
sed -n "$var1,$var2"p |
All times are GMT -5. The time now is 11:43 AM. |