Search Suggest

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

Đăng nhận xét