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?
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?
Try this awk one liner:
$ awk '$2=$2"@gmail.com"' file
a [email protected] n
d [email protected] h
e [email protected] y
-i. Sigh.... Anyway - newer versions of gawk support -i inedit to change the original file too if that's a consideration.Using sed inline:
sed -i.bak 's/\(^[^ ]* *\)\([^ ]*\)\(.*\)$/\1\[email protected]\3/' file
This will save the changes in the original file itself.
[^ ]* means match anything except a space and .* means any 0 or more length text.sed -r 's/^\S+\s+\S+/&@gmail.com/' file is more readable and robust (GNU sed).sed.