Find the answer to your Linux question:
Results 1 to 3 of 3
How can I read file line by line I wont to read all lines and do same command to each line for example if I have directory's paths like ./Load_spcl_cldspn_trn3_Jun_09_2007_153838.ch_log ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    31

    How can I read file line by line

    How can I read file line by line
    I wont to read all lines and do same command to each line
    for example if I have directory's paths like

    ./Load_spcl_cldspn_trn3_Jun_09_2007_153838.ch_log
    ./Load_spcl_cldspn_trn4_Jun_09_2007_153939.ch_log
    ./Load_spcl_cldspn_trn5_Jun_10_2007_071734.log
    ./Load_spcl_cldspn_trn4_Jun_09_2007_160253.ch_log
    ./Load_spcl_cldspn_trn3_Jun_10_2007_072059.log
    ./Load_spcl_cldspn_trn4_Jun_10_2007_072317.log
    ./Load_spcl_cldspn_trn6_Jun_10_2007_072717.log

    and I wont to do this command
    ls -tg

  2. #2
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    Maybe something like
    Code:
    $for i in `ls -tg`;do somecommand "i";done

  3. #3
    Linux Newbie unchiujar's Avatar
    Join Date
    Oct 2006
    Posts
    194
    From the command line you can use:
    Code:
    ls <file name> |  xargs <command for each line>
    or
    
    xargs -a <file name> <command for each line>

Posting Permissions

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