String of exclusions failed.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String of exclusions failed.
# 1  
Old 10-18-2018
String of exclusions failed.

We are in a conversion where a list of six digit numbers needs to be excluded from an existing report. As new ones are added we have an ever longer string of "grep -v" commands like:
Code:
  grep -v 020516 | grep -v 020522 | grep -v 030132 | \
  grep -v 030330 | grep -v 030357 | grep -v 050111 | \
  grep -v 070301 | grep -v 070319 | grep -v 070321 | \
  grep -v 090907 | grep -v 090914 | \
   ...........

Today we got "fork failed - too many processes"

The above is preceded by a grep that reads the report to filter out lines without an error code and pass them to many lines of "grep -v"s.

My question is how to fix this? Is there a better way to exclude lines than a string of "grep -v" commands?

TIA

We are using SCO Unix.
# 2  
Old 10-18-2018
Not sure about the grep version you run, but how about
- collecting the numbers in a file and use grep -Ff pattern-file
- using "alternation" like grep -v "number\|number\|..."
# 3  
Old 10-18-2018
Quote:
Originally Posted by RudiC
- collecting the numbers in a file and use grep -Ff pattern-file
- using "alternation" like grep -v "number\|number\|..."
or, just to be complete (although the way your problem sounds, i'd prefer RudiCs first method of a pattern file), using:

Code:
grep -ve "first" -ve "second" -ve "third" .....

I hope this helps.

bakunin
# 4  
Old 10-18-2018
@bakunin: yes, equivalent to alternation. The -v is needed only once.
# 5  
Old 10-18-2018
I couldn't find "-fF" in my Unix books or "man grep", but putting up to three "-ve" reduces the number of times I have to run it by nearly a third. Also runs faster.

Thank you, gentlemen.

I've used the command file for sed many times, but not grep.
# 6  
Old 10-18-2018
It's not one option, it's two options, both fairly standard AFAIK.

-f to load from a file.
-F to consider it to hold fixed strings instead of regexes.

Wouldn't it be so much nicer to have a file full of
Code:
string1
string2
string3

than a mess of grep statements marginally below the system limit?
# 7  
Old 10-18-2018
Quote:
Originally Posted by wbport
I couldn't find "-fF" in my Unix books or "man grep", but putting up to three "-ve" reduces the number of times I have to run it by nearly a third. Also runs faster.

Thank you, gentlemen.

I've used the command file for sed many times, but not grep.
Recent versions of grep have a -E option (to specify using extended regular expressions in patterns instead of the default basic regular expression) and a -F option (to specify using fixed strings instead of regular expressions in patterns).

Older versions of grep had an fgrep utility that behaved like newer versions behave with grep -F and older versions of grep had an egrep utility that behaved like newer versions with grep -E.

The -f file option and option-argument have been specified for a long time but might not have been around when SCO UNIX was in active development. On systems that have a -f option, -f file specifies using a file named file to get a list of patterns instead of (or in addition to) getting them from the command line.

Note that if you use an option that requires an option-argument, that option must be specified last if you combine a group of options in one command-line argument. The command-line:
Code:
grep -vFf file

is a request to print lines from standard input that do not match (-v option) fixed strings (-F option) found in the file named file (-f file option and option-argument).
On the other hand the command-line:
Code:
grep -vfF file

is a request to print lines from the file named file (an operand on the command-line) that do not match (-v option) found in the file named F (-fF option and option-argument).

For SCO UNIX, I would suggest that you try:
Code:
egrep -v 'number|number|...'

The egrep uses EREs instead of BREs for the pattern (which allows you to use | as a separator between alternatives in a single pattern) instead of specifying multiple patterns with -e options. The length of a command-line given to the shell is essentially unlimited, but if you're creating a script you may be using an editor that limits line lengths to about 2,048 bytes per line. That should be more than enough to create a pipeline that won't break active process count limits even if the SCO UNIX egrep doesn't have a -f option.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

2. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. UNIX for Advanced & Expert Users

Port redirection with exclusions

Hi folks, I have an application that is acting up. I have another machine with a replacement application on it but because of the naming structure clients are using I cannot change the name to the replacement machine as it is also used to access other applications. The host OS is Centos 5.6... (0 Replies)
Discussion started by: beddo
0 Replies

4. Solaris

Cygwin X Server error: xdmcp fatal error session failed session 23 failed for display

Hi, i got the following error when i tried to access the cygwin x server from a windows XP PC. "xdmcp fatal error session failed session 23 failed for display" Alternatively, when i tried to access the same Cygwin X Server from another windows XP PC which is on a different LAN... (3 Replies)
Discussion started by: HarishKumarM
3 Replies

5. Solaris

Find command with exclusions

Hi All I need to find the biggest files on our system BUT excluding some directories. I.E Find / -size +10000 (excluding 'platform'|'db' ..etc) |sort -n > file I tried grep -v but that can only do one expression at a time. Tried /usr/xpg4/bin/grep but cant use -v Please help Chris (5 Replies)
Discussion started by: JTS911
5 Replies

6. AIX

to identify failed pv

Hi friends,.... am sindhiya, i have joined as AIX level 1 support. help me to identify the failed pv in vg which has some 4 physical volumes? (2 Replies)
Discussion started by: sindhiya
2 Replies

7. AIX

SFTP Failed---Request for subsystem 'sftp' failed on channel 0

Hi, While I am trying SFTP my machine to another unix machine , it was working fine till 10 min back. But now i am getting the below error "Request for subsystem 'sftp' failed on channel 0" Could you please someone help me to solve or analyise the root cause... Cheers:b:, Mahiban (0 Replies)
Discussion started by: mahiban
0 Replies

8. Shell Programming and Scripting

Failed to replace string with "sed"

Hi folks, I have the following configuration file: tofu:/tmp # cat bitbandConfig.properties maestroIp=10.10.10.10 maestroPort=2020 adminPlayPath=<Streaming Agent IP>:2021/streamingGateway/GetPlayList ###This part should not be changed### adminPlayVODProtocol=http username=iptv... (7 Replies)
Discussion started by: nir_s
7 Replies

9. Shell Programming and Scripting

Failed to substitute string with "<>"

Hi folks, I have the following template file: application.filePath.core = /core-RIGHTV/Html/ application.filePath.xbip = /xbip-RIGHTV/Html/ translator.rootContext = /translator_<schame_name>/ I need to substitute the string in the third line "<schema_name>" with $SCHEMA_NAME I ran the... (4 Replies)
Discussion started by: nir_s
4 Replies

10. Shell Programming and Scripting

Failed to insert string into file before line

Hi folks, I have the following program: #! /bin/ksh set -xv export grepDataSource="</data-sources>" export DB_HOST=tornado export SCHEMA_NAME=IAS10G export dataSource=data-sources.xml sourceString="<data-source class=\"oracle.jdbc.pool.OracleConnectionCacheImpl\" name=\"RiGHTvDS\"... (7 Replies)
Discussion started by: nir_s
7 Replies
Login or Register to Ask a Question