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 Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-14-2006
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
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
  #2 (permalink)  
Old 08-15-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 579
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
  #3 (permalink)  
Old 08-15-2006
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
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?)
  #4 (permalink)  
Old 08-15-2006
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
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 ???
  #5 (permalink)  
Old 08-15-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
assuming the file name has no embedded blanks:

Code:
find . -name \*hotel_rates.* | xargs ls -lt | nawk '/Aug 02 2006/ { print $NF }'

  #6 (permalink)  
Old 08-15-2006
rosh0623 rosh0623 is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 29
works

Cool Thanks man !!
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0