Results 1 to 7 of 7

Thread: GREP problems

  1. #1
    Join Date
    Mar 2003
    Location
    Chile
    Posts
    1

    Exclamation Unanswered: GREP problems

    Hi there!!!

    My problem is the following:

    I am traying to made a script that should do the following:

    1. Get from the system the Current month (e.g. Apr)
    2. Get from the system the Current date (e.g. 02)
    3. Concatenate those 2 values (e.g. Apr 02)
    4. Then list the files that are in a certian directory an then grep them in order to get only the files that were updated only that date and create a file with the list of the files grepped

    The script that I made is the following:

    ##Start##
    month=`date +'"%h '`
    date=`date +'%d"'`
    time=$month$date

    ls -lt /pusa/nchs/bdr55/data/trace/*1200*|grep $time > /tmp/text
    ##End##

    Everytime that i run it, it failed with the following messahe:

    grep: 0652-033 Cannot open 04".

    when I ran the command manually, without variables its ran perfectly:

    ls -lt /pusa/nchs/bdr55/data/trace/*1200*|grep "Abr 02" > /tmp/text


    Could you please help on this issue?? what is wrong????

    Thanks in advance,
    Freddy

  2. #2
    Join Date
    Mar 2003
    Posts
    280
    I'm not sure I get it, you would like to list files in a directory that is changed today? Something like:

    find /pusa/nchs/bdr55/data/trace/ -name "*1200*" -ctime 0

    should do the trick. Check man find for details on find

    HTH
    /Lennart

  3. #3
    Join Date
    May 2003
    Posts
    2

    Re: GREP problems

    Hi Freddy

    change the grep statement to read

    grep "$time"

    instead of grep $time

  4. #4
    Join Date
    Apr 2001
    Location
    Netherlands
    Posts
    191
    Can't you use the find command, with the mtime option?
    Ruud Schilders
    -----------------
    Oracle DBA
    e-mail : ruud@schilders.it
    URL : www.schilders.it
    Twitter : www.twitter.com/ruudschilders

  5. #5
    Join Date
    Dec 2002
    Posts
    104
    Hello,

    check for value u getting in $time

    It seems that variable($time) is getting wrong value.Because from example, it seems u want month name for which u should use %b instead of %h to put value in $month

    Pooja

  6. #6
    Join Date
    Aug 2003
    Location
    INDIA
    Posts
    1
    hello pooja,
    We can use both the commands date +%d and date +%h to get the month . The problem lies at the &time instead of '&time' .He said he can get it correctly when he wexecutes manually. But if he runs as a script he needs to give '&time' .Am I right?

  7. #7
    Join Date
    Jul 2003
    Location
    Edinburgh
    Posts
    35
    jwall was correct when (s)he said that the command should be grep "$time" rather than grep $time.

    The original command pipeline expects grep to search standard input for the string specified in the envvar time, which it will do if it is given an unique argument. In the latter case, the shell expands $time into Abr 04 which grep interprets as two arguments separated by a space, and tries to find the string Abr in the file 04. Hence the error. The other number in the error message is an error code from the command (smells like AIX from here ...).

    Putting grep '$time' into a script will not work. We want the shell to expand the envvar, wheras this will tell grep to find the literal string $time in stdin.

    Alex

    Originally posted by mshankars
    hello pooja,
    We can use both the commands date +%d and date +%h to get the month . The problem lies at the &time instead of '&time' .He said he can get it correctly when he wexecutes manually. But if he runs as a script he needs to give '&time' .Am I right?

Posting Permissions

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