ALBI
ALBI

Reputation: 721

Editing a column in a text file using shell script

I have a text file:

a b n
d f h 
e f y

I want to edit it and make it like:

a [email protected] n
d [email protected] h 
e [email protected] y

How can I do this? Is there any command which can help?

Upvotes: 0

Views: 2425

Answers (3)

potong
potong

Reputation: 58371

This might work for you (GNU sed):

sed -i 's/\S\+/&@gmail.com/2' file

Upvotes: 0

anubhava
anubhava

Reputation: 784998

Using sed inline:

sed -i.bak 's/\(^[^ ]* *\)\([^ ]*\)\(.*\)$/\1\[email protected]\3/' file

This will save the changes in the original file itself.

Upvotes: 2

user000001
user000001

Reputation: 33317

Try this awk one liner:

$ awk '$2=$2"@gmail.com"' file
a [email protected] n
d [email protected] h
e [email protected] y

Upvotes: 5

Related Questions