sed doesn't have incrementing ability, but you can do it with
awk.
Code:
awk 'BEGIN{ i=1 } { print $0 " " i ".US" ; i++ }' file.txt
BEGIN{ i=1 } presets the variable
i to a starting value. This can be left out if you want the count to start at 0.
print $0 prints the entire input line, which is then followed by a space, the current value of
i, and the rest of the desired string. (Note that in the print command literal strings must be quoted, and any unprotected spaces between the values are ignored.)
Finally,
i++ increments a variable by one for each line processed. (Use
i+=2, for example, to step by other increments)
However, awk doesn't have inline editing ability, so you have to send the output to a separate file.
And here's another variation for creating a file with the desired sequence (10 lines, in this case).
Code:
awk 'BEGIN{ for ( i=1; i<=10; i++ ){ print "Thanks " i ".US" } }' > file.txt
awk is the most powerful of the text processing tools generally used in scripting. It is, in fact, a full scripting language of its own.
Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one...ined-part-one/
I
highly recommend learning at least the basics of
sed, and
awk, as well as
regular expressions, which are used by them and many other applications. They are the backbone tools of text processing.