Deleting line with sed command in unix/linux
Hello guys,
I studied about this command but didn't tried and it is a screen shot to show you,how a sed command deletes the line from file.
sed "/$textsearch/d" My_list
will delete any line in the file My_list that matches $textsearch.I want to know how exactly i use this command to delete the line from the file so that it doesn't appear next time I open the file ?
Deleting line with sed command in unix/linux
This is one of the procedure through which you can delete particular line from the file.There are some options are being added with the command.The options are used to count and detect the number of lines.
Code:
(echo "g/${textsearch}/d"; echo 'wq') | ex -s My_list
"g/${textsearch}/d" this line performs the 'delete' operation and 'wq' Writes the file to disk and 'Quits' after updating the file.
Deleting line with sed command in unix/linux
I faced this situations,when I tried to execute the above written command and searched a lot of description but not getting success to execute without any help.
On the other section of the search means beside of this code,I got a command which is able to delete the same and matching with the first posted thread but you have to do some little bit changes to before executing this command.
sed "/$textsearch/d" My_list >tmp
mv tmp My_list
Deleting extraneous characters with sed command
You can delete the extraneous characters like <,*,#,@,etc.The file are full of these type of text and you want remove those extraneous characters from the file and when we open the file,the file should be looks like without any extraneous characters :
You have to do some small changes in the code :
Code:
sed -n -e "s/^[^<]*<\([^>]*\)>.*/\1/p"
The code will delete all the specified characters from the file,this command would be executed with the help of echo command.
Deleting line with sed command in unix/linux
Hi,
This is one more example which can do this same means the deletion of extraneous characters on the command prompt.The command is combination of cut command.
It would look same as the above suggested command by the expert members.
$echo "Good Text<extraneous characters" | cut -d "<" -f1
Just specify the characters in the double court associated with cut command.
Re: Deleting line with sed command in unix/linux
Hi Fragman,
use this command:
sed -e "s/$textsearch//g" My_list > New_My_list
where New_My_list will be ur new file name which contains all the content of the file My_list except those lines.
Try this.
Quote:
Originally Posted by
Fragman
Hello guys,
I studied about this command but didn't tried and it is a screen shot to show you,how a sed command deletes the line from file.
sed "/$textsearch/d" My_list
will delete any line in the file My_list that matches $textsearch.I want to know how exactly i use this command to delete the line from the file so that it doesn't appear next time I open the file ?