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
part of a filename flame_eagle Shell Programming and Scripting 8 02-28-2008 11:18 AM
Report of duplicate files based on part of the filename sudheshnaiyer UNIX for Dummies Questions & Answers 1 12-18-2007 04:31 PM
read a part of information from txt and put into the script happyv Shell Programming and Scripting 18 10-27-2006 10:46 AM
Wanted to eliminate numeric part from a filename Sona UNIX for Dummies Questions & Answers 8 07-20-2006 02:49 PM
list only identical filename HAA Shell Programming and Scripting 6 05-17-2006 11:04 AM

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

Join Date: Sep 2006
Posts: 209
read a part of filename from the list in the script

how can i read a part of filename from the list in the script?

all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number.

CDBACKUPFILEJOHN00001
CDBACKUPFILEMARRY00004
CDBACKUPFILEPETER00003

I will use: ls -l CDBACKUPFILE*.archived to list out file.

can I write a script to read a file "list.txt" and the script can put JOHN, MARRY, PETER, etc into the statement?
  #2 (permalink)  
Old 10-20-2006
Indalecio Indalecio is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sweden
Posts: 59
Hi
You could first discard the CDBACKUPFILE string by using a substring command based on the length of this first parameter.
Then use a filter to remove any number from your string, or alternatively a substring command if your seq number has a fixed length.

I don't give you the code as I don't have the time to test it I just hope this will indicate you how to do the job.
  #3 (permalink)  
Old 10-20-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
You can try something like this :
Code:
while read name
do
   ls -l CDBACKUPFILE${name}*.archived
done <list.txt

Jean-Pierre.
  #4 (permalink)  
Old 10-20-2006
napolayan napolayan is offline
Registered User
  
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Quote:
Originally Posted by happyv
how can i read a part of filename from the list in the script?

all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number.

CDBACKUPFILEJOHN00001
CDBACKUPFILEMARRY00004
CDBACKUPFILEPETER00003

I will use: ls -l CDBACKUPFILE*.archived to list out file.

can I write a script to read a file "list.txt" and the script can put JOHN, MARRY, PETER, etc into the statement?
Hi, here's a suggestion. i dont hv unix on this comp so plz try it out n lemme know the results


ls -l|while read line
do
#the followng will first cut out the CDBACKUPFILE, then using awk, i'll specify
#0 as the field delimiter and print out the first field, which will be the name
cut -c 1-12|awk -F"0" '{print $1}'>file.txt
done
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 07:12 PM.


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