Perhaps something like this:Code:#!/bin/sh # run through every file named 0.txt, 1.txt, ..., 9.txt for f in [0-9].txt; do cat $f >> links.txt done
This is probably really simple, and the reasoning is ridiculous, but I am a scripting noob, and have only a small clue...
Let's say I have 10 text files, each with one line of text. I want to cat each file, take that one line of text, and append it to a separate file (i.e. if I have files 1-10.txt, I want to end up with a file 'links.txt' that has ten lines of text, one from each of the ten files). This is ridiculous...
I then needed to take each line from links.txt and open them in firefox under new tabs. I have this part done. I tested it and all is well (nice time to learn a loop!), but I am having one hell of a time figuring out how to take 10 files and put their info into one file. I tried 'cat *.txt >> links.txt' but that basically puts all of the info in paragraph form, where I need something that will do one line of text, then do a newline, then add a line of text, newline, and so forth.
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
Perhaps something like this:Code:#!/bin/sh # run through every file named 0.txt, 1.txt, ..., 9.txt for f in [0-9].txt; do cat $f >> links.txt done
Don't worry Ma'am. We're university students, - We know what We're doing.
'Ruiat coelum, fiat voluntas tua.'Datalogi - en livsstil; Intet liv, ingen stil.
Something like this may work: It's not tested, but you may be able to refine it.
!#/bin/bash
#
for file in `find . -type f -name "*.txt"`
do
cat $file >> links.txt
echo >> links.txt
done
Pretty neat Radar, posting at the same time![]()
Don't worry Ma'am. We're university students, - We know what We're doing.
'Ruiat coelum, fiat voluntas tua.'Datalogi - en livsstil; Intet liv, ingen stil.
Thanks a TON! I ended up using a bit of both suggestions:
#!/bin/sh
for file in [0-9].txt
do
cat $file >> links.txt
echo >> links.txt
done
I found some things regarding this 'echo >> xxxx' to create new lines in the final text file, but I could NOT get them to work. I think I was trying to do this OUTSIDE of the loop. One minor question though... what if you had a file 25.txt? Can you say [0-9][0-9].txt to represent two digit numbers, or...? (I told you I was a noob...)
Thanks again for the help. I know that it is probably trivial for someone that knows what they are doing, but I am pretty excited about it. When I built the second half of this script yesterday, I couldn't believe that it worked. Needless to say, with a few successes on my end, and the wonderful help I have received on some other projects, I just want to automate EVERYTHING. Now, if I could only automate dinner, and the dishes...
I promise to read more of my scripting guides, so I don't have to trouble you guys with trivial garbage...
Last edited by vwgtiturbo; 06-07-2006 at 08:28 PM.
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
Originally Posted by vwgtiturbo
Best way to learn is to try!
So yes you canCode:[conor@finland:~]$ touch 25.txt [conor@finland:~]$ for i in [0-9][0-9].txt; do echo $i; done 25.txt[0-9] will match a single character, ranges 0 - 9. Similarly, [A-Z] will match any capitol letter, [a-z] will match any lowercase letter, and you can mix and match like [A-Za-z] to match any capitol OR lowercase letter.
I lost my self-respect at Wes' Rib House
Man, I really need to get hopping on my reading... Every month or so, I learn something WAY cool, something that is really basic that ties things together for me so that I finally understand something. It is quite fun, actually being able to do things that once seemed impossible. Granted, it's not like I am learning programming or anything insane like that, but it is nice to be able to automate/test things in a quick manner...
Asus A8V Deluxe Mobo
AMD Athlon64 X2 4400 -939
2GB Crucial DDR3200 Dual-Channel
ATi AiW 9800 Pro 128DDR
Audigy2 ZS
Sony DRU-810 DVD+RW DL
3 x Maxtor MaxLine SATA 160Gb 16Mb Cache
1 x Maxtor MaxLine SATA 300Gb 16Mb Cache
1 x Maxtor MaxLine SATA 120Gb 16Mb Cache
Yeah, I see you beat me to the punch!Originally Posted by redhead
![]()
Check out the resources in the sticky post here in shell scripting. Good reading.Originally Posted by vwgtiturbo
Bookmarks