Removing command line arguments from string list

I am passing a list of strings $list and want to remove all entries with --shift=number, --sort=number/number/..., --group=number/number/... Also are removed whether upper or lower case letters are used

For example the following will all be deleted from the list

--shift=12
--shift=2324
--sHIFT=6273
--sort=12/23
--sort=12/34/890
--group=12/34/5/7
--gRoup=123/4/5/7/890/234

Currently I have coded

set strLst = `echo $argv[$firstArg-$lastArg]  \
  | awk '{sub(/--shift=[0-9]*|--sort=[0-9]*|--group=[0-9]*/, "")};1'`

Of course, the --sort and --group part do not work with number sequences separated by '/'.

How about this:

set strLst = `echo $argv[$firstArg-$lastArg]  \
| grep -ivE '[-]-((shift=[0-9]+)|(sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$'`

try this

v="$( egrep -vi 'sort|group|shft' $list)"

I have tried the below but is returning nothing.

echo "--shift=3 --sort=10/12/14 --group=12/14/15 m08-npt30.ry m06-npt10.ry jcdint-z30-01.ry n06-z30.ry jcdint-z30-02.ry" | grep -iE -v '[-]-(shift=[0-9]*|group=[0-9][/0-9]*|sort=[0-9][/0-9]*)'

Yes because you need a newline between each option:

With my updated version:

$ echo -e "--shift=3\n--sort=10/12/14\n--group=12/14/15\nm08-npt30.ry\nm06-npt10.ry\njcdint-z30-01.ry\nn06-z30.ry\njcdint-z30-02.ry" | grep -ivE '[-]-((shift=[0-9]+)|(sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$'
m08-npt30.ry
m06-npt10.ry
jcdint-z30-01.ry
n06-z30.ry
jcdint-z30-02.ry
$

If no newlines try putting | tr ' ' '\n' in the pipeline.

1 Like

I tried but getting egrep: unrecognized option '--shift=3'

set string = "--shift=3 --sort=10/12/14 --group=12/14/15 m05-npt08.xt jcdint-z30.xt m04-npt06.xt m03-npt04.xt m02-npt02.xt"

egrep -vi 'sort|group|shft' $string

egrep: unrecognized option '--shift=3'
Usage: egrep [OPTION]... PATTERN [FILE]...
Try `egrep --help' for more information.

$ echo "--shift=3 --sort=10/12/14 --group=12/14/15 m08-npt30.ry " \
"m06-npt10.ry jcdint-z30-01.ry n06-z30.ry jcdint-z30-02.ry" |
tr ' ' '\n' |
grep -ivE '[-]-((shift=[0-9]+)|(sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$'
m08-npt30.ry
m06-npt10.ry
jcdint-z30-01.ry
n06-z30.ry
jcdint-z30-02.ry
$

Yes, I done

set strLst = `echo $argv[$firstArg-$lastArg] | tr ' ' '\n' \
  | grep -ivE '[-]-((shift=[0-9]+)|(sort|group)=[0-9]+/[0-9]+(/[0-9]+)*)$' | tr '\n' ' '`