Find the answer to your Linux question:
Results 1 to 5 of 5
I have a line this is a universe this is a hello world want to print 2 field to last field, so doing following {for(i=5;i<=NF;i++) printf $i} but I am ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    19

    How to give space using printf

    I have a line

    this is a universe this is a hello world

    want to print 2 field to last field, so doing following

    {for(i=5;i<=NF;i++) printf $i}

    but I am getting output like this (withought space between)

    isauniversethisisahelloworld

    please suggest how can get the space here, like
    is a universe this is a hello world

  2. #2
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    What language are you trying to do this in?

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    19
    Shell..


    sorry i forgot to mention, correct syntax

    awk '{for(i=5;i<=NF;i++) printf $i}'

  4. #4
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796
    In that case, there's no need to do all that work to accomplish what you're trying to do. Here's a simpler solution:
    Code:
    string="this is a universe this is a hello world"
    echo ${string:5}
    I highly recommend you check out http://tldp.org/LDP/abs/html

  5. #5
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by shorye View Post
    Shell..


    sorry i forgot to mention, correct syntax

    awk '{for(i=5;i<=NF;i++) printf "%s ",$i}'
    see red fonts

Posting Permissions

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