Proper Expression To Not Include A String...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Proper Expression To Not Include A String...
# 1  
Old 12-23-2009
Proper Expression To Not Include A String...

I have a folder of scripts:

Code:
bash:/folderpath/> ls
beginFile.sh
beginFileBackup.sh
beginAnother.sh
beginAnotherBackup.sh
beginJunk.sh
beginJunkBackup.sh

I'd like to be able to call just one (beginFile.sh) using this type of scheme:

Code:
#Run the beginFile script without the word "Backup" in it.
echo /folderpath/beginFile[^Backup]*.sh | xargs -n1 sh
#Run the rest of scripts with the exception of the beginFile.sh script.
echo /folderpath/begin[^File[^Backup]]*.sh | xargs -n1 sh

Also, what If I did it this way:

I know it isn't right, but can anyone provide the correct syntax? Also what If I want to run the rest of the scripts, except the beginFile.sh and the *Backup.sh file (i.e. beginAnother.sh and beginJunk.sh)?


Code:
ls /folderpath | grep 'begin[^File.sh]' | xargs -n1 sh

Would the expression change because I'm using grep?


Thanks in advance for all answers.

Last edited by mrwatkin; 12-23-2009 at 04:43 PM..
# 2  
Old 12-23-2009
If you set extglob (shopt) to yes in bash, or standard in ksh93 you can do this:

Just run beginfile:
Code:
/folderpath/beginFile.sh

run he rest of the scripts:
Code:
/folderpath/!(beginFile.sh)

run the rest of the scripts, except the beginFile.sh and the *Backup.sh file
Code:
/folderpath/!(beginFile.sh|*Backup.sh)


Last edited by Scrutinizer; 12-23-2009 at 05:16 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk If expression - Return string if not true

Hi, I have the following txt file List_With_Duplicates.txt; a,1,1 b,3,4 c,5,2 d,6,1 e,3,3 f,3,7 When I run the command awk -F ',' '{if($2==$3){print $1","$2","$3}}' List_With_Duplicates.txt I get the following output; a,1,1 e,3,3 This works! as I've compared the 2nd & 3rd... (7 Replies)
Discussion started by: mmab
7 Replies

2. Shell Programming and Scripting

awk evaluating a string as a math expression

Hi, I am writing a script in awk trying to replace strings that are math expressions with their result. For example, I have a file that looks like this: 5-1 32/8-1 4*12 17+1-3 I would like to get the following output: 4 3 48 15 I tried doing it the following way (using the "bc"... (8 Replies)
Discussion started by: avi.levi
8 Replies

3. Shell Programming and Scripting

String regular expression

Hi, temp="/usr=25,/usr/lib=12" How to get only dir names with out values. I tried like below but no use. tmp=${temp##*,} echo $tmp o/p: /usr/lib=12 expected o/p: /usr /usr/lib ---> in array (13 Replies)
Discussion started by: munna_dude
13 Replies

4. Shell Programming and Scripting

Extract all proper names from string with awk

I want to extract the proper names with awk from a very long string, like: õ(k): &lt;/span&gt;<br /><a something="pls/pe/person.person?i_pers_id=3694&amp;i_topic_id=2&amp;i_city_id=3372&amp;i_county_id=-1" target="_blank"><b>Gary Oldman</b></a> (George Smiley)<br /><a... (12 Replies)
Discussion started by: lyp
12 Replies

5. Shell Programming and Scripting

grep a string with include next 100 line

Hi, I have a log file which has number of lines from that i have to grep a string like this 03:22:19,287 while greping this string i have to grep next lines to the maximum of finding the word (MORE...) the stack is like this ************* 22/11/2011 03:22:19,287 232290646 ERROR... (2 Replies)
Discussion started by: thelakbe
2 Replies

6. Shell Programming and Scripting

How can awk search a string without using regular expression?

Hello, Awk seem treat the pattern as regular expression, how can awk search not using regular expression? e.g. just represent for "", not "A" or "a" . I don't want to add backslash . (2 Replies)
Discussion started by: 915086731
2 Replies

7. Shell Programming and Scripting

regular expression format string in one line.

Hi All, @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $day=091023; $day_combine = $day; $day_combine =~ s/({2})({2})({2})/20$1-$months-$3/; Instead of three lines, is possible to combine the last two lines into a single line? means no need assign $day to $day_combine... (2 Replies)
Discussion started by: jimmy_y
2 Replies

8. Shell Programming and Scripting

Help: Regular Expression for Negate Matching String

Hi guys, as per subject I am having problem with regular expressions. Example, if i got a string "javax.servlet.http.HttpServlet.service" that may occurred anywhere within a text file. How can I used the negate pattern matching of regular expression? I tried the below pattern but it... (4 Replies)
Discussion started by: DrivesMeCrazy
4 Replies

9. Shell Programming and Scripting

validate a string against a regular expression

Hi there i have a script which will create unix user accounts. Id like to validate the entered string so that it is specifically 8 characters or less and consists of only ! not Is there a way to validate a string against a regular expression.. i.e size=`printf "$var | wc -m` ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. UNIX for Dummies Questions & Answers

Regular Expression - match 'b' that follows 'a' and is at the end of a string

Hi, I'm struggling with a regex that would match a 'b' that follows an 'a' and is at the end of a string of non-white characters. For example: Line 1: aba abab b abb aab bab baa I can find the right strings but I'm lacking knowledge of how to "discard" the bits that precede bs.... (2 Replies)
Discussion started by: machinogodzilla
2 Replies
Login or Register to Ask a Question