LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-21-2013, 05:58 PM   #1
nexsus
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Rep: Reputation: Disabled
Help on Adding one counter loop at the end of each line in a file


Hello All,
I have file a.txt
I want to add a counter loop at the end of each line in a file
ill explain:
i have a site h**p://test.test=Elite#1
i want to add a a counter to the number at the end of the file, that it will be like this
h**p://test.test=Elite#1
h**p://test.test=Elite#2
h**p://test.test=Elite#3
etc,
and finally the complete list will be saved to a local file
Can any one help me on this?

Last edited by nexsus; 11-21-2013 at 06:07 PM.
 
Old 11-21-2013, 06:19 PM   #2
vasis
LQ Newbie
 
Registered: Jul 2013
Posts: 19

Rep: Reputation: Disabled
Something like this maybe:

Code:
for x in {1..10}; do
 echo "http://test.test=Elite#$x" >> file.txt;
done
I am confused as to what "a.txt" is though... Do you want to read from "a.txt"? Please let me know if I completely misunderstood your question...
 
Old 11-21-2013, 06:20 PM   #3
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,195
Blog Entries: 10

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Code:
for i in {0..9} ; do echo "h**p://test.test=Elite#$i" ; done
http://tldp.org/LDP/abs/abs-guide.pdf
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ

Duh, I forget the file write. Silly me.

Last edited by Habitual; 11-21-2013 at 06:21 PM.
 
Old 11-21-2013, 06:27 PM   #4
nexsus
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hey.
i want to save the links to a txt file (a.txt just random name)
that after that ill import it to my appz that know to read links

i have a proxy site with a lot of of links in this convention
h**p://test.test=Elite#1
h**p://test.test=Elite#2
h**p://test.test=Elite#3
etc,

i need to make a counter loop only on the number that it will be like this
h**p://test.test=Elite#1
h**p://test.test=Elite#2
h**p://test.test=Elite#3000

and finally all the convention links name will be in my file that called a.txt

ill check now what you guys post
TNX
 
Old 11-21-2013, 06:42 PM   #5
nexsus
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank You much Guys,
its work

and thank you Habitual for the useful links.
 
Old 11-21-2013, 10:06 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Please mark as SOLVED once you have your solution
 
Old 11-22-2013, 08:26 AM   #7
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,195
Blog Entries: 10

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by nexsus View Post
Thank You much Guys,
its work

and thank you Habitual for the useful links.
You are very welcome.
 
Old 11-22-2013, 09:06 AM   #8
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Rep: Reputation: 31
Quote:
#!/bin/bash

number=0

for line in $(cat a.txt)
do
echo "$line$number"
let number+=1
done > tmpFile

mv tmpFile a.txt
Sorry for getting this in so late. I tryed to post this code yesterday but my post did not work.

Last edited by youngstorm; 11-22-2013 at 09:10 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Path at end of line Ra'Jiska Linux - Newbie 5 06-16-2013 08:28 PM
[SOLVED] AWK Adding a Period at the end of a line metallica1973 Programming 11 11-26-2012 03:05 PM
[SOLVED] Adding text to end of a particular line in bash dagummit Linux - General 7 11-30-2010 11:22 AM
adding new line at end of file airikah Programming 3 11-08-2003 05:27 AM


All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration