Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Ridiculous script needs....
Results 1 to 9 of 9

Thread: Ridiculous script needs....

  1. #1

    Ridiculous script needs....

    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

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    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.

  3. #3
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630
    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

    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  4. #4
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    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.

  5. #5
    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

  6. #6
    Quote Originally Posted by vwgtiturbo
    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...)

    Best way to learn is to try!

    Code:
    [conor@finland:~]$ touch 25.txt
    [conor@finland:~]$ for i in [0-9][0-9].txt; do echo $i; done
    25.txt
    So yes you can [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

  7. #7
    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

  8. #8
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630

    Talking

    Quote Originally Posted by redhead
    Pretty neat Radar, posting at the same time
    Yeah, I see you beat me to the punch!

    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  9. #9
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630
    Quote Originally Posted by vwgtiturbo
    Man, I really need to get hopping on my reading
    Check out the resources in the sticky post here in shell scripting. Good reading.

    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Similar Threads

  1. script
    By try in forum Linux - General Topics
    Replies: 0
    Last Post: 12-15-2008, 07:43 AM
  2. A Suspicious Script
    By Carrym in forum Windows - General Topics
    Replies: 1
    Last Post: 03-22-2007, 12:30 PM
  3. Can Anyone Help With A Simple Script??
    By Gary Penner in forum Programming
    Replies: 1
    Last Post: 02-01-2005, 07:03 PM
  4. Probs in a script called from another script
    By Outlaw in forum Programming
    Replies: 1
    Last Post: 03-12-2004, 02:54 PM
  5. iptables script...
    By Mor_gath in forum Programming
    Replies: 5
    Last Post: 12-24-2001, 04:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •