#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Find a date value from a line in file


    Dear Team,

    Please help me in providing the solution to extract a date value one by one may in a loop to a variable from a line in a file sample.txt, the content of the file is as below.

    Code:
    99999999999                 99999999999992013051699999999999999999
    99999999999              12399999999999992013051799999999999999999
    This date value has a fixed index location in the file from 43 to 50.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Say
    awk '{ print substr($0,42,8) }' sample.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Originally Posted by balram0179
    Please help me in providing the solution to extract a date value one by one may in a loop to a variable from a line in a file sample.txt.
    This is one way to do it in a shell script:
    Code:
    $ cat t
    99999999999                 99999999999992013051699999999999999999
    99999999999              12399999999999992013051799999999999999999
    
    $ cat ~/bin/test.sh
    while read line
    do
     dt=${line:41:8}
     echo "My date is: $dt"
    done < t
    
    $ test.sh
    My date is: 20130516
    My date is: 20130517

IMN logo majestic logo threadwatch logo seochat tools logo