How to grep a string in todays file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grep a string in todays file
# 8  
Old 04-05-2010
Code:
$
$
$ # list all files that start with "ERProcess"
$ ls -1 ERProcess*
ERProcessBD0404201099999.txt
ERProcessBD0405201099999.txt
$
$ # show the contents of yesterday's file
$ cat ERProcessBD0404201099999.txt
04/04/2010 line_1 => blah
04/04/2010 line_2 => lostER
04/04/2010 line_3 => blah
$
$ # show the contents of today's file
$ cat ERProcessBD0405201099999.txt
04/05/2010 line_1 => blah
04/05/2010 line_2 => lostER
04/05/2010 line_3 => blah
$
$ # list just today's file
$ ls -1 ERProcessBD`date '+%m%d%Y'`*.txt
ERProcessBD0405201099999.txt
$
$ # list just today's file and then grep for the word "lostER" in it
$ ls -1 ERProcessBD`date '+%m%d%Y'`*.txt | xargs grep "lostER"
04/05/2010 line_2 => lostER
$
$

tyler_durden
# 9  
Old 04-05-2010
I can create a file with this command in my system:

Code:
touch `date '+%m%d%Y'`.txt

and it give 04052010.txt

and to be able to find a pattern inside that file under a directory:
Code:
find . -type f -name `date '+%m%d%Y'`.txt -mtime -1 | xargs grep -i pattern

is this what you are looking for?
# 10  
Old 04-05-2010
Thanks Tyler. The last option you mentioned was the one i was looking for, but it didnt work!

Hi Eagle:

It gives me this error:
find: invalid predicate '- (the file name)
# 11  
Old 04-05-2010
Quote:
Originally Posted by DallasT
...The last option you mentioned was the one i was looking for, but it didnt work!
...
What's the error message that you see on your terminal ?
Can you copy/paste the part of your terminal screen where you run the command and encounter the error ?

tyler_durden
# 12  
Old 04-05-2010
Quote:
Originally Posted by DallasT
Thanks Tyler. The last option you mentioned was the one i was looking for, but it didnt work!

Hi Eagle:

It gives me this error:
find: invalid predicate '- (the file name)
try this one then:

Code:
find . -type f -name "*`date '+%m%d%Y'`.txt" -mtime -1 | xargs grep -i pattern

# 13  
Old 04-05-2010
Hi Eagle: I get this error:

ERProcessBD04052010*.txt: No such file or directory

Hi Tyler, once i execute the command, it just sits and nothing happens.

I would also want to inform that there are 2 files from todays date in the same folder. They both are duplicates of each other. I wouldnt care which one does the command read, it can be either of the two. They both however have the same naming convention but are named differently.
# 14  
Old 04-05-2010
Try this one, it should work like this:

Code:
find . -type f -name "ERProcessBD`date '+%m%d%Y'`*" -mtime -1 |  xargs grep "lostER"

or
Code:
find . -type f -name "ERProcessBD`date '+%m%d%Y'`*" |  xargs grep "lostER"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. UNIX for Beginners Questions & Answers

How to list todays file in perticular folder?

How to list todays file in perticular folder Moved thread to appropriate forum (9 Replies)
Discussion started by: pspriyanka
9 Replies

3. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

4. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

5. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

how to get todays file name

Hi ! there can you please tell me how to get full files having today date like if i have files like this(below) , i want to grep only sra + today's date + what ever thing is there after date . grep `sra*$date*.csv` >>> i tried this one but its not working . sra28-08-2011xyz.csv... (1 Reply)
Discussion started by: sravan008
1 Replies

8. Shell Programming and Scripting

How to list todays file

Hi Friends, How to list todays file from a directory listing of files for amny dates. I tried with the following options but not working : find . -name "esi01v*" -mtime 1 -ls find . -name "esi01v*" -ctime 1 -ls find . -name "esi01v*" -mtime 1 Please advise (19 Replies)
Discussion started by: unx100
19 Replies

9. Shell Programming and Scripting

using todays date to create a report using grep

What i'm trying to do is to use grep to search through a few files for a selected daemon and only report on today's date. I think I got it sorted apart from in the txt file the date has 2 gaps between the month and the day, and the way I have the date format only puts in one gap any help to get... (3 Replies)
Discussion started by: MBN
3 Replies

10. Shell Programming and Scripting

want to delete timestamp from todays file

i want to delete the time stamp from the file which have a date of yester day 640878 Nov 6 09:08 fbres.01.20031106:09:08:30 here is what my ls -lt command shows in current directory it want it to be 640878 Nov 6 09:08 fbres.01.20031106 thanks (5 Replies)
Discussion started by: maverick
5 Replies
Login or Register to Ask a Question