Sed command delete pattern match keyword from file

# cat emaillist
shahzad@example.com
shahzad.in@example.com
shahzad.out@example.com
alam@example.com
alam.out@example.com

Delete any matched keyword form file.  I am deleting here .in@example.com
Use following sed command:

# sed '/.in@example.com/d' emaillist
Output:
shahzad@example.com
shahzad.out@example.com
alam@example.com

Redirect output in new file

# sed '/.in@example.com/d' emaillist >emailnew
# cat emailnew
shahzad@example.com
shahzad.out@example.com
alam@example.com

Delete keyword using –I option under file

# sed -i '/.in@example.com/d' emaillist
# cat emaillist
shahzad@example.com
shahzad.out@example.com
alam@example.com

alam.out@example.com
Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment