The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching files inside directory kylethesir UNIX for Dummies Questions & Answers 4 06-06-2008 01:44 AM
searching files through all subdirectories beneath the current directory milagros Shell Programming and Scripting 5 05-15-2007 04:00 PM
Searching for files over 30 days old in current directory cxredd4 Shell Programming and Scripting 18 06-11-2006 02:16 AM
Searching for directory Enigma23 Shell Programming and Scripting 8 04-08-2005 09:31 PM
directory searching st00pid_llama Shell Programming and Scripting 2 05-10-2004 07:21 PM

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 12-09-2005
srivsn srivsn is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 32
Searching files in a directory.Urgent

Hi everyone,

I need to search files starting with RPT_0, RPT_1,........ in a directory. How can I implement that through a shell script. Also I want to read the last line of each file after searching them. Can someone help me out in this regard.

One more thing how I can extract a particular pattern in the last line of the file.
Eg: ### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16
In the above line I have extract RPT507A BBW and convert that space between RPT507A and BBW with underscore( _ ).

Thanks in advance...
srivsn
  #2 (permalink)  
Old 12-09-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Will this help you??

Code:
for i in `ls -1 RPT_*`
do
last=`tail -1 $i`
pat=`expr "$last" : '.*(\(.*\)).*'`
pat=`echo $pat | sed 's/ /_/'`
print $pat
done
  #3 (permalink)  
Old 12-09-2005
srivsn srivsn is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 32
Renaming and deleting old file. Pls help

Hi everyone,

Thx a lot Mona for your reply. It worked.

Little modifications. I am extremely new to this Unix. Please help.

After extracting the name from the code below, I want to move the contents of the old file to the new one extracted. We have to delete the old file. Also concatinate the new file name with DD(current day). I will give you a example below.

RPT_1.txt(old filename)
### Job 65 (RPT507A BBW ): 390 lines, 7 pages, 10/26/2005 01:55:16(last line of file RPT_1.txt)

By using the logic given in reply mail, I will get the output as RPT507A_BBW

Now I want to concatinate that with DD(day).
So my output is RPT507A_BBW09 (09 is today)

Also I want to append all the files in RPT_1.txt to new filename RPT507A_BBW09
and delete the old file RPT_1.txt.

The same logic has to be implemented for all the files in the directory starting with RPT_*.txt.

Thanks to all,
srivsn
  #4 (permalink)  
Old 12-09-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Code:
day=$(date +%d)
for i in `ls -1 RPT_*`
do
last=`tail -1 $i`
pat=`expr "$last" : '.*(\(.*\)).*'`
pat=`echo $pat | sed 's/ /_/'`
pat=$pat$day
mv $i $pat
done
  #5 (permalink)  
Old 12-09-2005
srivsn srivsn is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 32
Parameterising the file pattern

Hi Mona/everyone,

Thx again for Mona . I need to pass RPT_ as parameter to the shell script which I have below. Say I have created a shell script rn.sh with the code in last reply. Now instead of RPT_ hard coding, I need to give a parameter there and I am using this script in some other job. There I will give the parameter value which includes path name along file name(RPT_). Could you help me in this.....Please give the syntax also.

Thanks,
srivsn
  #6 (permalink)  
Old 12-09-2005
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Quote:
Originally Posted by srivsn
Hi Mona/everyone,

Thx again for Mona . I need to pass RPT_ as parameter to the shell script which I have below. Say I have created a shell script rn.sh with the code in last reply. Now instead of RPT_ hard coding, I need to give a parameter there and I am using this script in some other job. There I will give the parameter value which includes path name along file name(RPT_). Could you help me in this.....Please give the syntax also.

Thanks,
srivsn
This is very simple. Just pass "RPT_" as a parameter to your script. Change the for loop alone like below

Code:
for i in `ls -1 $1*`
Closed Thread

Bookmarks

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 08:06 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