add a word in end of lines & edit with +1 in every line
Welcome
-- let's say this is the text file Code:
echo Play 1 > 1.txt i want to do much like this till 100.txt how ? and i have other text file Code:
gedit 1.txt to 100.txt in other file i have something look like this Code:
ABC just examples but i want to do different thing please help ? and srry for little speak |
You can write a script to do this.
Code:
#!/bin/bash |
thx for reply
but i mean in the text file i don't wana create 1.txt 2.txt etc i want to write 1.txt 2.txt in the text file got it ? lets say i have text file ok i want to make teams with a letter "A" then numbers then .US A1.US A2.US A3.US i want A -> till 100 .US ... ... A100.US i want just increase the number in every line please answer the topic question 1.txt etc . and how to insert a word in end of lines some of my friends says i should use sed but i dont know what the command to use to do that . Please Help >< |
Same process just change touch for echo and redirect into your file.
|
A shorter way to do it, using brace expansion
Code:
printf "%s" A{1..100}.US$'\n' > file.txt *Edit: changed it to use printf instead, as echo appears to also preserve the space inserted between each string by the brace expansion. To add something to the end of every line in a file, try this: Code:
sed -i 's/$/.jpg/' file.txt Here are a few useful sed references. http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt |
Thanks Guyz
but there 1 more thing i want to know how the text file (1) Code:
Thanks number 1 increase by 1 in every line + .US Code:
Thanks 1.US |
Thanks anyway i did that by using Find and Replace :D
Thank u Very Much |
Code:
|
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 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 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. |
Another one:
Code:
awk '$0 = sprintf("%s %d.US",$0,++c)' file |
Thx guyz
|
Nifty version colucix. It just goes to show that there are many ways to accomplish the same thing.
I was trying to keep it to a basic level for my example. We don't want to get in too deep with a new user. That kind of thing comes with experience. |
Quote:
|
All times are GMT -5. The time now is 04:48 AM. |