Sponsored Content
Full Discussion: agrep: pattern too long
Top Forums Shell Programming and Scripting agrep: pattern too long Post 302174965 by drl on Wednesday 12th of March 2008 06:23:56 PM
Old 03-12-2008
Hi.

My experiments:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate [ac]grep, copying a group of lines.

#  ____
# /
# |   Infrastructure BEGIN

echo
set -o nounset

debug=":"
debug="echo"

## The shebang using "env" line is designed for portability. For
#  higher security, use:
#
#  #!/bin/sh -

## Use local command version for the commands in this demonstration.

set +o nounset
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) grep agrep cgrep
set -o nounset

echo

FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE

# |   Infrastructure END
# \
#  ---

echo
echo ' Results from grep:'
grep '29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05' $FILE

echo
echo ' Results from agrep:'
agrep '29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05' $FILE

echo
echo ' Results from agrep with -d:'
agrep -d seconds '29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05' $FILE

echo
echo ' Results from agrep with -d -k:'
agrep -d seconds -k '29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05' $FILE

echo
echo ' Results from agrep with -d <>:'
agrep -d seconds '<29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05>' $FILE

echo
echo ' Results from cgrep:'
cgrep +I2 -+w seconds '29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05' $FILE

exit 0

Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
grep (GNU grep) 2.5.1
agrep (local) - no version provided.
cgrep (local) - no version provided.

 Input file data1:
seconds
nothing here

seconds
junk
29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05
junk

seconds
junk
still no match
more junk

 Results from grep:
29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05

 Results from agrep:
29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05

 Results from agrep with -d:
agrep: pattern too long

 Results from agrep with -d -k:
agrep: pattern too long

 Results from agrep with -d <>:
agrep: pattern too long

 Results from cgrep:
========================================
seconds
junk
29 06 0e 2b 06 01 04 01 9d 64 03 08 02 01 05 05
junk

The source for the successful cgrep may be obtained from: cgrep home page

You'll need to compile and install it, but it went easily for me. If that's not an acceptable option for you, then perhaps one of the awk experts will stop by and help ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Vi - "The replacement pattern is too long"

Hi, I am trying to replace a value in a script with another value. I am performing a vi command from another script. vi - ${conf_path}/CANCEL_CD_PART2.txt<<! :%s/RANGE/${btch_range}/g :wq ! 'RANGE' is the current value that the parm in the other script has (PARM1=RANGE), along with... (3 Replies)
Discussion started by: hern14
3 Replies

2. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

3. Shell Programming and Scripting

How to specify two delimiters in agrep for record definition ?

Hi all, How to specify two delimiters in agrep for record definition, one for the beginning of the record and the other for the end ? Most of examples I see so far only specify 1 delimiter, e.g. agrep -d '^From ' 'pizza' mbox. But that won't work for me. I need to 2 delimiters to indicate the... (2 Replies)
Discussion started by: qiulang
2 Replies

4. Shell Programming and Scripting

Why does '$$' means an empty line in agrep -d '$$'

Hi all, Why does '$$' means an empty line in agrep -d '$$'. I did not know that '$$' can be seen as an empty line in regular expression. So did I miss something here ? Thanks! (4 Replies)
Discussion started by: qiulang
4 Replies

5. Shell Programming and Scripting

Replacing or removing a long list of pattern by using awk or sed

Input: >abc|123456|def|EXIT| >abc|203456|def|EXIT2| >abc|234056|def|EXIT3| >abc|340056|def|EXIT4| >abc|456000|def|EXIT5| . . . Output: def|EXIT| def|EXIT2| def|EXIT3| def|EXIT4| def|EXIT5| . . My try code: (9 Replies)
Discussion started by: patrick87
9 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

8. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

9. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

10. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.10 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 02:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy