Pattern matching notation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern matching notation
# 8  
Old 03-29-2013
Thanks, I'll test it later, i'm on holiday, i 'll come back at april 3.

Have a nice week-end.
# 9  
Old 03-29-2013
Like Hanson44 notes, you need curly brackets around the shell variable, because the underscore can be part of the variable name. Also, the pattern needs to be quoted for use with -name. For a single pattern try this:
Code:
find /usr -name "${type}_log*.log.${date}.*"

--
[????????] is equivalent to [?] and \? and this means a single actual question mark.

Last edited by Scrutinizer; 04-02-2013 at 12:52 PM..
# 10  
Old 03-29-2013
As we do not know what to discriminate against, i.e. what to exclude, I think a simple * would do:
$type*.log.$date.*
# 11  
Old 03-29-2013
I know it seems like it might work, but I don't think it works:
Code:
$ cat temp.sh
touch exploitation_ora.log.2013-03-28.001
touch server.log.2013-03-28.tar.gz

date=2013-03-28
instance=ora

for type in exploitation server; do
  echo Looking just for type = $type
  find . -name "${type}_log*.log.${date}.*" -print
done

Code:
$ ./temp.sh
Looking just for type = exploitation
Looking just for type = server

Might not it be better to let the poster test the previous solution that seems to work fine, instead of confusing the situation with other possible solutions? The thread will still be here April 3rd. Smilie
# 12  
Old 03-29-2013
@hanson44: I used the OP's specification in the first post and then that should be
Code:
touch exploitation_log_ora.log.2013-03-28.001
touch server_log.log.2013-03-28.tar.gz

I am not trying to confuse matters but the OP did ask for a unified pattern.
# 13  
Old 03-29-2013
As almost usual, specifications / samples in posts #1 and #6 are contradictory if not mutually exclusive unless we assume a variable called type_log:
post #1:
Code:
$type_log_$instance.log.$date.001
$type_log.log.$date.tar.gz

post #6:
Code:
exploitation_ora.log.2013-03-28.001
server.log.2013-03-28.tar.gz

@hanson44: As there's no _log in the filenames taken from post #6, that find won't work, of course. If you use the real file names, touched above, it will:
Code:
$ for type in exploitation server; do   echo Looking just for type = $type; ls $type*.log.$date.*; done
Looking just for type = exploitation
exploitation_ora.log.2013-03-28.001
Looking just for type = server
server.log.2013-03-28.tar.gz

# 14  
Old 04-02-2013
Thanks a lot, it's working.
This site should be reimbursed by social insurance. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

2. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

3. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

4. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

5. Shell Programming and Scripting

Pattern matching notation

Hello I have two kinds of logs like server.logserver.log.2013-07-27.001i want to create a variable which look like this (with a pipe) log_name=server.(log|log.$YYYY-MM-DD.)But i tried many cases but it didn't work. Is it possible ? If yes, can you help me. (6 Replies)
Discussion started by: amazigh42
6 Replies

6. Shell Programming and Scripting

Pattern matching notation

Hello, I want to match this patterns IS01ORA IS02ORA ... ... IS08ORA With that : ISORA But it doesn't work, can you correct it ? Thanks (8 Replies)
Discussion started by: amazigh42
8 Replies

7. Shell Programming and Scripting

[DATE] Pattern matching notation

Hello, I want to verify the format date like 2013-03-08 (YYYY-MM-DD) It doesn't work because the pattern matching notation below returns false while the date is right. Can you help me ? Thanks in advance case "$6" in (-0-0 | -1-1 | -1-2 | -1-3) # Nothing, OK ! ;; (*) echo 'Fatal,... (4 Replies)
Discussion started by: amazigh42
4 Replies

8. Shell Programming and Scripting

Convert decimal notation to ANSI point code notation

wondering if anyone has any thoughts to convert the below thru a shell script Convert decimal signalling point notation to ANSI point code notation There is a site that does that conversion but i need to implement the solution in a shell script.....Thoughts.... OS: Solaris 9 ... (4 Replies)
Discussion started by: aavam
4 Replies

9. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question