SED - how to delete everything after a special character on every line?


#1

Transfered from Linux Config Disqus comments:

Question:

how to delete everything after a special character on every line?

#2

Hi Pazis,

You forgot to mention what your special character is. But let’s suppose that your special character is “@” and you wish to remove everything after it on every line using SED command:

Here is a content of sample file sed.txt:
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer

to remove everything after @ symbol we can use the following command:

$ sed s/@[^@]*$// sed.txt

For example:

$ cat sed.txt 
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer
sed scriting@linuxcareer
$ sed s/@[^@]*$// sed.txt 
sed scriting
sed scriting
sed scriting
sed scriting
sed scriting

Hope this helps…

Lubos


#3