modify entries in a list of names :: should be easy enough, right?
I would like to take a list of names in a file and append text to the beginning and end of them.
eg. ========= BEFORE ========= cat ./names.txt jade joe john harry ========= AFTER ========= cat ./names.txt email: jade@somedomain.com email: joe@somedomain.com email: john@somedomain.com email: harry@somedomain.com |
Hi,
Code:
sed 's/\(.*\)/email: \1@somedomain.com/' names.txt Hope this helps. Add the -i flag to make changes in place. |
paste names.txt email.txt // puts texts side by side james email@example.com
Maybe you meant cat email.txt >> names.txt which will append email.txt after names.txt james email@example.com |
I'd use GNU awk for that, although sed will work fine.
If you don't have the gnu awk, install it. It's a nuclear powered chainsaw for text processing.
gawk '{print $1 "@somedomain.com"}' names.txt ought to do the job for you... |
Hi,
Quote:
Code:
gawk '{print "email: " $1 "@somedomain.com"}' names.txt @linux_evangelist: If this is solved can you put up the [SOLVED] flag (First post -> Thread Tools). Hope this helps. |
Now I understand what linux_evangelist meant. jade => Email: jade@somedomain.com
Definitely gawk or sed. If you did have a file with "Email: ", another with "jade" and another with "@somedomain.com", paste would work but not like the gawk or sed example posted above. paste -d "" file1 file2 file3 > file123. cat file123 would result in Email: jade@somedomain.com . |
Thank you druuna for the correction
Yes, druuna is right (thanks!) I misread the original post slightly and left off the prefix.
Code:
gawk '{print "email: " $1 "@somedomain.com"}' names.txt Code:
gawk '{printf "email: %s@somedomain.com\n", $1}' names.txt I like gawk better than sed for this kind of problem because it's easier for me to read and figure out months or years later. Unix sed is fast and effective, but it has such a terse syntax that it's hard to do anything complex in it without creating alphabet soup! |
thanks guys.
|
All times are GMT -5. The time now is 03:13 PM. |