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
get substr? syamkp Shell Programming and Scripting 6 03-31-2008 02:08 AM
awk or substr ramky79 UNIX for Dummies Questions & Answers 3 03-13-2007 08:18 PM
Substr deepakwins UNIX for Dummies Questions & Answers 9 02-14-2007 12:58 AM
Using substr Klashxx Shell Programming and Scripting 2 05-08-2006 07:58 AM
How to use awk substr ? sabercats Shell Programming and Scripting 1 02-10-2006 07:01 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 07-11-2007
colesga colesga is offline
Registered User
  
 

Join Date: Mar 2007
Location: London
Posts: 7
awk substr

Hi

I have multiple files that name begins bidb_yyyymm. (yyyymm = current year month of file creation).

What I want to do is look at the files and where yyyymm is older than 1 month I want to remove the file from the server.

I was looking at looping through the files and getting the yyyymm from the filename and comparing it to the cuurent dates yyyymm.

for file in `ls *.gz`
do
now=`date '+%Y%m'`
fileext=awk substr($file,6,6)
if [$now-$fileext] <> 0
then
rm $file
fi

I was looking at awk substr to get the part of the filename i require but could not get this to work.

Has anyone done anything like this before or can point me in the right direction to achieve my objectives.

Cheers
Gary
  #2 (permalink)  
Old 07-11-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
filext=$( expr substr "$file" 6 6)
Code:
filext=$( echo "$file" | cut -c6-12 )
  #3 (permalink)  
Old 07-11-2007
colesga colesga is offline
Registered User
  
 

Join Date: Mar 2007
Location: London
Posts: 7
Thanks

Changed my mind in the end and did the following

find $log_dir/*.gz -ctime +$zip_days | xargs rm -f
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 04:45 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