Results 1 to 6 of 6

Thread: [SOLVED] Spacing between for do loop

  1. #1
    Join Date
    Feb 2008
    Location
    Malta
    Beans
    126
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    [SOLVED] Spacing between for do loop

    Hi,

    I have the following statment which is getting the values from two text files and merging them into another file:

    for i in `seq -w 1 1300`;do for a in Final.txt query.txt;do cat $a | sed -n "$i p" >> Result.txt;done;done

    The output into the file Result.txt is as follows:

    Value in final.txt
    Value in query.txt
    Value in final.txt
    Value in query.txt
    Value in final.txt
    Value in query.txt
    Value in final.txt
    Value in query.txt
    Value in final.txt
    Value in query.txt

    I would like to leave a line Spacing between the Value in query.txt and final.txt to have the following output:

    Value in final.txt
    Value in query.txt

    Value in final.txt
    Value in query.txt

    Value in final.txt
    Value in query.txt

    I have tried using the following statement, however i do not receive the desired output:

    for i in `seq -w 1 1300`;do for a in Final.txt query.txt;do cat $a ;echo /n | sed -n "$i p" >> Result.txt;done;done

    Any advice?? Thanks!

  2. #2
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Spacing between for do loop

    I think you might way to change:

    Code:
    echo /n
    to

    Code:
    echo ""
    Edit:
    You don't need the "\n" for echo. Just ""
    Last edited by sdennie; May 12th, 2008 at 09:42 AM. Reason: I was wrong
    Don't try to make something "fast" until you are able to quantify "slow".

  3. #3
    Join Date
    Feb 2008
    Location
    Malta
    Beans
    126
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Spacing between for do loop

    That appears to be generating a loop.... rather then outputing the content into the results.txt, it is quickly displaying everything on screen and never ends...

    Though the output on the screen is still not formatted correctly...

    Any other tips m8?

    Thanks!

  4. #4
    Join Date
    Jan 2007
    Location
    $here ? $here : $there
    Beans
    3,717
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Spacing between for do loop

    Looking at that a bit closer, I think the echo is in the wrong place (but, I'm tired and might be wrong). Try:

    Code:
    for i in `seq -w 1 1300`;do for a in Final.txt query.txt;do cat $a | sed -n "$i p" >> Result.txt ;done echo "" >> Result.txt;done
    Note: It's much easier to debug that stuff if you break it into multiple lines...
    Don't try to make something "fast" until you are able to quantify "slow".

  5. #5
    Join Date
    Feb 2008
    Location
    Malta
    Beans
    126
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Spacing between for do loop

    Thanks!!

    Indeed it was in the incorrect place!

  6. #6
    Join Date
    Sep 2006
    Location
    France.
    Beans
    Hidden!
    Distro
    Lubuntu Development Release

    Re: [SOLVED] Spacing between for do loop

    Moved to PT, and marked as solved
    | My old and mostly abandoned blog |
    Linux user #413984 ; Ubuntu user #178
    J'aime les fraises.
    Nighty night me lovelies!

    | Reinstalling Ubuntu ? Please check this bug first ! |
    | Using a ppa ? Please install ppa-purge from universe, you may need it should you want to revert packages back |
    | No support requests by PM, thanks |

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
  •