If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > GREP problems

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-03, 18:12
t006sfh t006sfh is offline
Registered User
 
Join Date: Mar 2003
Location: Chile
Posts: 1
Exclamation 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
Reply With Quote
  #2 (permalink)  
Old 03-12-03, 17:49
lelle12 lelle12 is offline
Registered User
 
Join Date: Mar 2003
Posts: 86
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
Reply With Quote
  #3 (permalink)  
Old 05-01-03, 10:35
jwall jwall is offline
Registered User
 
Join Date: May 2003
Posts: 2
Re: GREP problems

Hi Freddy

change the grep statement to read

grep "$time"

instead of grep $time
Reply With Quote
  #4 (permalink)  
Old 05-11-03, 10:10
Ruudboy Ruudboy is offline
Registered User
 
Join Date: Apr 2001
Location: Netherlands
Posts: 173
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
Reply With Quote
  #5 (permalink)  
Old 07-15-03, 11:09
pooja pooja is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 08-09-03, 06:13
mshankars mshankars is offline
Registered User
 
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?
Reply With Quote
  #7 (permalink)  
Old 08-10-03, 14:37
chillies chillies is offline
Registered User
 
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

Quote:
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On