Sponsored Content
Top Forums Shell Programming and Scripting Excluding patterns from a list Post 302605316 by kristinu on Wednesday 7th of March 2012 08:33:25 AM
Old 03-07-2012
I did it like this.

Code:
set strLst = `echo $argv[$firstArg-$lastArg] | tr ' ' '\n'  \
  | grep -ivE --   '(--check|--check-colpos)'  \
  | grep -ivE --   '(--sort|--sort-fields)'    \
  | grep -ivE --   '(--group|--group-table)'   \
  | grep -ivE --   '(--shift|--shift-table)'   \
  | grep -ivE --   '(-v|--vrb-level)'  \
  | grep -ivE --   '(-q|--quiet)'      \
  | grep -ivE --   '(-u|--usage)'      \
  | grep -ivE --   '(-e|--examples)'   \
  | grep -ivE --   '(-h|--help)'       \
  | grep -ivE --   '( (--shift=[0-9]+) | (--shift-table=[0-9]+) )'  \
  | grep -ivE --   '--((sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$' | tr '\n' ' '`

I would need a bit of assistance in using getopts. I had considered it long time ago but not been very good of using it in a way I want.

---------- Post updated at 08:33 AM ---------- Previous update was at 08:30 AM ----------

Ok, in my code I have he following. How would you tackle the procedure using getopts using ksh. My plan is to convert my scripts to ksh eventually.

Code:
# --Read Command Line Arguments---------------------------------------------------------------------

# Set echo to recognize both the -n flag and backslashed escape sequences
set echo_style = "both"

# Perform numeric calculations using bc.
alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`'

# --Read Command Line Arguments---------------------------------------------------------------------

set ierr = 0
set iarg = 0
set opt_chkColPos = 0
set opt_sortFlds = 0
set opt_groupTbl = 0
set opt_shiftTbl = 0
set opt_verbose = 0
set opt_quiet = 0
set opt_usage = 0
set opt_examples = 0
set opt_help = 0

set vrb_usrInputFlag = 0
set Def_vrbLevel = 1
set Def_shiftLen = 3

set arg_fullNamesLst = ""
set narg = $#argv
while ($iarg < $narg)

  MATH iarg = $iarg + 1
  set arg = $argv[$iarg]
  set usrInputFlag = `echo $arg | awk '/=/ {print 1}; ! /=/ {print 0}'`
  set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}' | tr '[:lower:]' '[:upper:]'`
  set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`

  switch ($opt)

    # -- Optional Arguments ------------------------------------------------------------------------

    case "--CHECK":                         # Separates numbers from characters.
    case "--CHECK-COLPOS":
      set opt_chkColPos = 1
      breaksw

    case "--SORT":
    case "--SORT-FIELDS":
      set arg_sortPtn = $par
      set opt_sortFlds = 1
      breaksw

    case "--GROUP":
    case "--GROUP-TABLE":
      set arg_groupPtn = $par
      set opt_groupTbl = 1
      breaksw

    case "--SHIFT":
    case "--SHIFT-TABLE":
      set arg_shiftLen = $par
      set opt_shiftTbl = 1
      breaksw

    case "-V":
    case "--VRB-LEVEL":
      set arg_vrbLevel = $par
      set opt_verbose = 1
      set vrb_usrInputFlag = $usrInputFlag
      breaksw

    case "-Q":
    case "--QUIET":
      set opt_quiet = 1
      breaksw

    case "-U":
    case "--USAGE":
      set opt_usage = 1
      breaksw

    case "-E":
    case "--EXAMPLES":
      set opt_examples = 1
      breaksw

    case "-H":
    case "--HELP":
      set opt_help = 1
      breaksw

    default:
      set arg_fullNamesLst = "$arg_fullNamesLst $arg"
      breaksw

  endsw

end   # while

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed/awk help to match list of patterns and remove from org file

Hi, From the pattern mentioned below remove lines based on pattern range. Conditions 1 Look For all lines starting with ALTER TABLE and Ending with ; and contains the word MOVE.I wanto to remove these lines from the file sample below. Note : The above pattern list could be found in... (1 Reply)
Discussion started by: rajan_san
1 Replies

2. Shell Programming and Scripting

finding and removing patterns in a large list of urls

I have a list of urls for example: Google Google Base Yahoo! Yahoo! Yahoo! Video - It's On Google The problem is that Google and Google are duplicates as are Yahoo! and Yahoo!. I'm needing to find these conical www duplicates and append the text "DUP#" in from of both Google and... (3 Replies)
Discussion started by: totus
3 Replies

3. UNIX for Dummies Questions & Answers

script to search patterns inside list of files

>testfile while read x do if then echo $x >> testfile else fi if then echo $x >> testfile else fi done < list_of_files is there any efficient way to search abc.dml and xyz.dml ? (2 Replies)
Discussion started by: dr46014
2 Replies

4. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

5. UNIX for Dummies Questions & Answers

List files older that 7 days in a dir, excluding all subdirs

Hi, I would like to list all files, older than 7 days, in a directory, but exclude all subdirectories in the find command. If I use find . -type f -mtime +7 all files in the subdirs are also included. How can I exclude them? Regards, JW (6 Replies)
Discussion started by: jwbijl
6 Replies

6. Shell Programming and Scripting

Retrieve lines that match any occurence in a list of patterns

I have two files. The first containing a header and six columns of data. Example file 1: Number SNP ID dbSNP RS ID Chromosome Result_Call Physical Position 787066 SNP_A-8575395 RS6650104 1 NOCALL 564477 786872 SNP_A-8575125 RS10458597 1 AA ... (13 Replies)
Discussion started by: Selftaught
13 Replies

7. Shell Programming and Scripting

Using perl to grep a list of patterns from an input file

I have been struggling to grep a file of NGrams (basically clusters of consonants or Consonant and Vowel) acting as a pattern file from an Input file which contains a long list of words, one word per line. The script would do two things: Firstly read a text pattern from a large file of such... (5 Replies)
Discussion started by: gimley
5 Replies

8. UNIX for Dummies Questions & Answers

[Solved] List Files With Multiple Name Patterns

Hi, We have created a script that would accept the an indicator as a parameter and archive files present in a directory. The indicator would drive what the name pattern of the files to be archived should be. If the indicator is 1, then the pattern to look out for is FACT*. If the indicator is... (2 Replies)
Discussion started by: jerome_rajan
2 Replies

9. Shell Programming and Scripting

Help needed in excluding certain word patterns

Hi, I need help with following. I need to exclude words that match following patterns a. more than length 4 (example SBRAP) b. contains mixture uppercase and lower case regardless of the length (example GSpD) File contains COFpC MCHX SP SNFCA GEH SBRAP DGICA JPMpE WFCpP GSpD AXL... (5 Replies)
Discussion started by: jakSun8
5 Replies

10. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies
case(n) 						       Tcl Built-In Commands							   case(n)

__________________________________________________________________________________________________________________________________________________

NAME
case - Evaluate one of several scripts, depending on a given value SYNOPSIS
case string ?in? patList body ?patList body ...? case string ?in? {patList body ?patList body ...?} _________________________________________________________________ DESCRIPTION
Note: the case command is obsolete and is supported only for backward compatibility. At some point in the future it may be removed entirely. You should use the switch command instead. The case command matches string against each of the patList arguments in order. Each patList argument is a list of one or more patterns. If any of these patterns matches string then case evaluates the following body argument by passing it recursively to the Tcl interpreter and returns the result of that evaluation. Each patList argument consists of a single pattern or list of patterns. Each pattern may con- tain any of the wild-cards described under string match. If a patList argument is default, the corresponding body will be evaluated if no patList matches string. If no patList argument matches string and no default is given, then the case command returns an empty string. Two syntaxes are provided for the patList and body arguments. The first uses a separate argument for each of the patterns and commands; this form is convenient if substitutions are desired on some of the patterns or commands. The second form places all of the patterns and commands together into a single argument; the argument must have proper list structure, with the elements of the list being the patterns and commands. The second form makes it easy to construct multi-line case commands, since the braces around the whole list make it unneces- sary to include a backslash at the end of each line. Since the patList arguments are in braces in the second form, no command or variable substitutions are performed on them; this makes the behavior of the second form different than the first form in some cases. SEE ALSO
switch(n) KEYWORDS
case, match, regular expression Tcl 7.0 case(n)
All times are GMT -4. The time now is 08:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy