Sponsored Content
Full Discussion: Pattern matching notation
Top Forums Shell Programming and Scripting Pattern matching notation Post 302785223 by amazigh42 on Monday 25th of March 2013 06:22:56 AM
Old 03-25-2013
Quote:
Originally Posted by anbu23
Can you show your complete command?
In magenta

Code:
#!/bin/bash
#########################################################################
valid() {
case "$1" in
        [E,F,Q,P][A,C,S][A,I,V,P][D,R,T,V]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        [PU][IPS][AGS][1-8]) ;;
        IS0[1-8]ORA ;;
        *) return 1 ;;
        esac

        case "$3" in
        [0-1][0-9]) ;;
        2[0-3]) ;;
        *) return 1 ;;
        esac

        case "$4" in
        [0-5][0-9]) ;;
        *) return 1 ;;
        esac

        case "$5" in
        server) ;;
        exploitation) ;;
        *) return 1 ;;
        esac

        OLDIFS="$IFS"
        IFS="-"
               set -- $6 # $6=YYYY, $2=MM, $3=DD
        IFS="$OLDIFS"

        case "$1" in
        [2-9][0-9][0-9][0-9]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        0[1-9]) ;;
        1[0-2]) ;;
        *) return 1 ;;
        esac

        case "$3" in
        0[1-9]) ;;
        [1-2][0-9]) ;;
        3[0-1]) ;;
        *) return 1 ;;
        esac

        return 0
}
process() {
echo "$1 $2 $3 $4 $5 $6"
}

        if ! valid $1 $2 $3 $4 $5 $6 # Ignore invalid lines
        then
                echo "$1 $2 $3 $4 $5 $6 is invalid"
        else
        process $1 $2 $3 $4 $5 $6
fi


Last edited by amazigh42; 03-25-2013 at 09:42 AM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

Pattern matching notation

Hello, I want to simplify two commands into one. 1st command $type_log_$instance.log.$date.0012nd command $type_log.log.$date.tar.gzInto blue brackets, How do I do to replace the pattern by a blank or _$instance ? $type_log?_$instance].log.$date.*Thank you. (13 Replies)
Discussion started by: amazigh42
13 Replies

6. 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

7. 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

8. 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

9. 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

10. 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
BUILTIN(1)						    BSD General Commands Manual 						BUILTIN(1)

NAME
builtin, !, %, ., :, @, {, }, alias, alloc, bg, bind, bindkey, break, breaksw, builtins, case, cd, chdir, command, complete, continue, default, dirs, do, done, echo, echotc, elif, else, end, endif, endsw, esac, eval, exec, exit, export, false, fc, fg, filetest, fi, for, foreach, getopts, glob, goto, hash, hashstat, history, hup, if, jobid, jobs, kill, limit, local, log, login, logout, ls-F, nice, nohup, notify, onintr, popd, printenv, pushd, pwd, read, readonly, rehash, repeat, return, sched, set, setenv, settc, setty, setvar, shift, source, stop, suspend, switch, telltc, test, then, time, times, trap, true, type, ulimit, umask, unalias, uncomplete, unhash, unlimit, unset, unsetenv, until, wait, where, which, while -- shell built-in commands SYNOPSIS
builtin [-options] [args ...] DESCRIPTION
Shell builtin commands are commands that can be executed within the running shell's process. Note that, in the case of csh(1) builtin com- mands, the command is executed in a subshell if it occurs as any component of a pipeline except the last. If a command specified to the shell contains a slash ``/'', the shell will not execute a builtin command, even if the last component of the specified command matches the name of a builtin command. Thus, while specifying ``echo'' causes a builtin command to be executed under shells that support the echo builtin command, specifying ``/bin/echo'' or ``./echo'' does not. While some builtin commands may exist in more than one shell, their operation may be different under each shell which supports them. Below is a table which lists shell builtin commands, the standard shells that support them and whether they exist as standalone utilities. Only builtin commands for the csh(1) and sh(1) shells are listed here. Consult a shell's manual page for details on the operation of its builtin commands. Beware that the sh(1) manual page, at least, calls some of these commands ``built-in commands'' and some of them ``reserved words''. Users of other shells may need to consult an info(1) page or other sources of documentation. Commands marked ``No**'' under External do exist externally, but are implemented as scripts using a builtin command of the same name. Command External csh(1) sh(1) ! No No Yes % No Yes No . No No Yes : No Yes Yes @ No Yes Yes { No No Yes } No No Yes alias No** Yes Yes alloc No Yes No bg No** Yes Yes bind No No Yes bindkey No Yes No break No Yes Yes breaksw No Yes No builtin No No Yes builtins No Yes No case No Yes Yes cd No** Yes Yes chdir No Yes Yes command No** No Yes complete No Yes No continue No Yes Yes default No Yes No dirs No Yes No do No No Yes done No No Yes echo Yes Yes Yes echotc No Yes No elif No No Yes else No Yes Yes end No Yes No endif No Yes No endsw No Yes No esac No No Yes eval No Yes Yes exec No Yes Yes exit No Yes Yes export No No Yes false Yes No Yes fc No** No Yes fg No** Yes Yes filetest No Yes No fi No No Yes for No No Yes foreach No Yes No getopts No** No Yes glob No Yes No goto No Yes No hash No No Yes hashstat No Yes No history No Yes No hup No Yes No if No Yes Yes jobid No No Yes jobs No** Yes Yes kill Yes Yes No limit No Yes No local No No Yes log No Yes No login Yes Yes No logout No Yes No ls-F No Yes No nice Yes Yes No nohup Yes Yes No notify No Yes No onintr No Yes No popd No Yes No printenv Yes Yes No pushd No Yes No pwd Yes No Yes read No** No Yes readonly No No Yes rehash No Yes No repeat No Yes No return No No Yes sched No Yes No set No Yes Yes setenv No Yes No settc No Yes No setty No Yes No setvar No No Yes shift No Yes Yes source No Yes No stop No Yes No suspend No Yes No switch No Yes No telltc No Yes No test Yes No Yes then No No Yes time Yes Yes No times No No Yes trap No No Yes true Yes No Yes type No No Yes ulimit No No Yes umask No** Yes Yes unalias No** Yes Yes uncomplete No Yes No unhash No Yes No unlimit No Yes No unset No Yes Yes unsetenv No Yes No until No No Yes wait No** Yes Yes where No Yes No which Yes Yes No while No Yes Yes SEE ALSO
csh(1), echo(1), false(1), info(1), kill(1), login(1), nice(1), nohup(1), printenv(1), pwd(1), sh(1), test(1), time(1), true(1), which(1) HISTORY
The builtin manual page first appeared in FreeBSD 3.4. AUTHORS
This manual page was written by Sheldon Hearn <sheldonh@FreeBSD.org>. BSD
February 23, 2005 BSD
All times are GMT -4. The time now is 10:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy