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
message in make files murad.jaber SUN Solaris 3 01-17-2008 04:44 AM
How can I make dos2unix in hp without renaming files? umen UNIX for Dummies Questions & Answers 2 01-14-2008 03:16 AM
iso files to make bootable dvd image bdsffl SUN Solaris 0 11-18-2006 02:25 AM
Need to make disk device files match mvizza HP-UX 0 06-01-2006 04:03 PM
Make files Dan Rooney Shell Programming and Scripting 2 04-23-2004 09:49 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 12-13-2006
fredao fredao is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 59
make use of the name of files

there are a number of files under the folder myfolder:

myfolder:

a_file_1 a_file_2 a_file_3 ...
b_file_1 b_file_2 b_file_3 ...
....

how can I write a script to do following:

if the name of the file starts with a, append the content of this file to file Final;
if the name of the file starts with b and the third field is greater than 2, append the content of this file to file Final for twice;
else, add a line " ================ ".

thanks!
  #2 (permalink)  
Old 12-13-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
what have you tried so far?
and where exactly are you stuck?
  #3 (permalink)  
Old 12-13-2006
fredao fredao is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 59
Quote:
Originally Posted by vgersh99
what have you tried so far?
and where exactly are you stuck?
I need to make different operation based on the names of the files under a directory. therefore, I need to write a script, and extract a substring of a name, and ... as shown in the example
  #4 (permalink)  
Old 12-13-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by fredao
I need to make different operation based on the names of the files under a directory. therefore, I need to write a script, and extract a substring of a name, and ... as shown in the example
ok. and what exactly have you tried so far?
  #5 (permalink)  
Old 12-13-2006
fredao fredao is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 59
Quote:
Originally Posted by vgersh99
ok. and what exactly have you tried so far?
here is the frame of my script:


find ./files/* |

while read file

do

if [ the name of the file start with "S" ]?
then
run ./a script ?
elif [ the name of the file start with a number ]?
then
run ./b script?
fi
done



##############
my problem is the place marked with "?"
  #6 (permalink)  
Old 12-13-2006
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
here's something to start with - good luck:
Code:
#!/bin/ksh

find . -type f | while read path
do

   file=$(basename "${path}")
   if [[ "${file}" == @(S*) ]]; then
      echo "[$path] run ./a script ?"
   elif [[ "${file}" == @([0-9]*) ]]; then
      echo "[$path] run ./b script ?"
   fi
done
P.S. pls do use vB Codes when posting code samples.

Last edited by vgersh99; 12-13-2006 at 04:15 PM..
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 10:21 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