Results 1 to 4 of 4

Thread: Need some help on 2 'for' loops

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Need some help on 2 'for' loops

    Hi,
    I need some help on scripting.
    I am doing a simple echo of lines and words from a file and I also want to echo the number of lines and words to it.
    Where can I get this help
    A simple script I am using is
    for i in `cat hostfile`
    do
    echo $i
    done
    And what I would like to do is something like this:
    for i in `cat hostfile`
    do
    for j in ((j=1;j<=1000;j++))
    do
    echo $i
    echo $j
    done
    Thanks a lot in advance

  2. #2
    Junior Member
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    To make it more clear, say a file has these names

    AAA
    BBB
    CCC
    DDD

    so the desired out put could be :

    1 AAA
    2 BBB
    3 CCC
    4 DDD

  3. #3
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,512
    Thanks
    17
    Thanked 799 Times in 511 Posts
    Rep Power
    10

    Default

    If you need output like that use cat command
    Code:
    cat -n file.txt
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  4. #4
    Junior Member
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Thanks

    The thing is , I am running few things to every line out put and I want the output to be numbered, for example

    I am removing 200 patches from a Sun server, so I have listed all the patches in a file and running patchrm command , but then I don't know how many are done or how many are left, so if I can get a numbered output, then it will help me.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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