Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I need a scrip that could print the 5th, 10th, 15th... of any file Any guess?...
  1. #1
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3

    printing the nth word of anyfile

    Hi,

    I need a scrip that could print the 5th, 10th, 15th... of any file

    Any guess?

  2. #2
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    What format is the file in? In other words, is there only one word on each line, or is it a series of words separated by spaces?
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  3. #3
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3
    There are words separated by spaces in the file

  4. #4
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    Code:
    awk '{print $2}' file.txt
    Obviously replacing file.txt with your file!

    Change the $2 to $10 to print the 10th word, etc.

    Code:
    awk '{print $2 " " $4}' file.txt
    This prints the 2nd and 4th words.
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  5. #5
    Linux Engineer scrarfussi's Avatar
    Join Date
    Aug 2006
    Posts
    1,029
    Hmmm is this homework

Posting Permissions

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