The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to search and replace text in same file Vrgurav Shell Programming and Scripting 1 04-25-2008 03:20 AM
Shell script to search for text in a file and copy file imeadows UNIX for Dummies Questions & Answers 8 04-20-2008 01:41 PM
How to search for text within compressed file HLee1981 UNIX for Advanced & Expert Users 8 09-06-2007 03:50 AM
Search file contain some text yuimyt UNIX for Dummies Questions & Answers 5 05-22-2006 01:31 PM
To search for a text in until i find that kotasateesh Shell Programming and Scripting 3 08-30-2005 05:32 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-14-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Stumble this Post!
find file with date and recursive search for a text

Hey Guyz I have a requirement something like this..

a part of file name, date of modification of that file and a text is entered as input.
like

Date : 080206 (MMDDYY format.)
filename : hotel_rates
text : Jim

now the file hotel_rates.ZZZ.123 (creation date is Aug 02 2006) should be found first and then the file should be opened in a read olny mode pointing to the first occurance of text 'Jim' in that file. when we press 'n' the next occurance of Jim should be visible and so on until the EOF. once searching Jim is done when we press q the control should be back to program.

all the files will be located in an archive folder with name /archive
and there'll be files with different dates like
hote_rates.XXX.333 Aug 01 2006
hotel_rates.YYY.222 Jul 30 2006
hotel_rates.ZZZ.123 Aug 02 2006
logistic_rates.ZZZ.123
logistic_rates.SSS.134

Now for the above example the file hotel_rates.ZZZ.123 should be found and it should be pinting to first occurance of Jim in that file after the user enters the input and hits enter.

Let me know if I made myself clear here..

Thanks,
Ronnie
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-14-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 523
Stumble this Post!
First of all, it sounds like homework, then sorry, we dont help in homework stuff.

Secondly, I want you to make it clear if this is the standard format of filename, hotel_rates.ZZZ.123 Aug 02 2006 ie filename and creation date? If answer is yes, then why you want to take input from user in 080206 format? Take input from user in XXX 99 9999 format means Aug 02 2006 format. If answer is no, then let me tell you that in UNIX there is nothing like creation date, we have mtime(modification), ctime(change) and atime(access time) in unix, so we can try to find your files on mtime basis.

I doubt that its the standard file format in your archive directory Filename + creation date, please confirm that, because it matters.

Regards,
Tayyab
Reply With Quote
  #3 (permalink)  
Old 08-15-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Stumble this Post!
Not a homwork

Hi Tayyab,

This is not a home work question. I started working in Unix just 6 months back. We have a daily synchronization of information with-in the internal systems of our company. like we recieve files like hotel_rates.ZZZ and once we post this data to database the file is stored in archive folder as (with a random 3 digit extention) hotel_rates.ZZZ.123 and once this file is pushed to archive folder there is no chance of modification. some times we might need to look up some information in these files which we posted, so This coding is a part of that.
We would need to retrieve the file with mtime.
so according to your notes, If we take the input as Aug 02 2006 would be better rather than 080206 right ?
let me know how to track the file and open it in readonly mode for recursive search (can we use 'less' in the shell script?)
Reply With Quote
  #4 (permalink)  
Old 08-15-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Stumble this Post!
i did this

hey I did this..

find . -name \*hotel_rates.* | xargs ls -lt | grep "Aug 02 2006"

this gives me ..
-rw-rw-r-- 1 user group 1025 Aug 02 2006 ./hotel_rates.ZZZ.147

can some one tell me how do I cut the file name from this line plz ???
Reply With Quote
  #5 (permalink)  
Old 08-15-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
assuming the file name has no embedded blanks:
Code:
find . -name \*hotel_rates.* | xargs ls -lt | nawk '/Aug 02 2006/ { print $NF }'
Reply With Quote
  #6 (permalink)  
Old 08-15-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Stumble this Post!
works

Cool Thanks man !!
Reply With Quote
  #7 (permalink)  
Old 08-16-2006
Registered User
 

Join Date: Jul 2005
Posts: 29
Stumble this Post!
question

hey how do we open a file and point it to a text/string we are searching..

for eg. we are searching for a string 'Jim' in file xxx.txt

in a shell program we have to open this file in read only mode and point it to first occurance of 'Jim'

like we do 'less xx.txt' and then type '/Jim' to find the occurance;...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mtime

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0