Alternative command to grep -w option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternative command to grep -w option
# 8  
Old 10-31-2015
Hi.

There are a number of grep-like codes that could be used in place of grep:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate alternate codes for "grep -w", ack, glark, peg, xtcgrep
# For ack, see:
# http://beyondgrep.com/
# For glark ( ruby ), see repository, or:
# https://github.com/jpace/glark
# For peg, see:
# http://www.cpan.org/authors/id/A/AD/ADAVIES/peg-3.10
# For xtcgrep, see:
# http://cpansearch.perl.org/src/MNEYLON/File-Grep-0.01/Grep.pm

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C ack glark peg xtcgrep

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

for program in ack glark peg xtcgrep
do
  pl " Results for program $program:"
  $program -w abc $FILE
done

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
ack (local) 2.12
glark version 1.8.0
peg (local) 3.10
xtcgrep (local) 1.5

-----
 Input data file data1:
abc
123abc456
123 abc
abc456
abc 456

-----
 Results for program ack:
abc
123 abc
abc 456

-----
 Results for program glark:
    1 abc
    3 123 abc
    5 abc 456

-----
 Results for program peg:
abc
123 abc
abc 456

-----
 Results for program xtcgrep:
abc
123 abc
abc 456

Except as noted, the work-alike codes are written in perl. Some codes produce color and/or line numbers, both of which can be de-selected with options. Results shown are with default options.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with grep, or alternative

say I have a big list of something like: sdg2000 weghre10 fewg53 gwg99 jwegwejjwej43 afg10293 I want to remove the numbers of any line that has letters + 1 to 4 numbers output: sdg weghre fewg gwg jwegwejjwej afg10293 (7 Replies)
Discussion started by: Siwon
7 Replies

2. Shell Programming and Scripting

Maxdepth command not working in AIX.Need alternative solution for this command

Hi All, I am trying to select 30 days older files under current directory ,but not from subdirectory using below command. find <Dir> -type f -mtime + 30 This command selecting all the files from current directory and also from sub directory . I read some documention through internet ,... (1 Reply)
Discussion started by: kommineni
1 Replies

3. Shell Programming and Scripting

Please suggest alternative to grep

Hi Experts, PFB my requirement: I have a file (named file1) containing numbers like: 372846078543002 372846078543003 372846078543004 372846078543005 372846078543006 I have another file (nemed file2)where lines containing these numbers(present in file1) are present; Eg: lppza087; <PERFB >... (6 Replies)
Discussion started by: niladri29
6 Replies

4. UNIX for Dummies Questions & Answers

alternative to the grep trick

Hi, We used to use the below commands often. ps -ef|grep bc ps -ef|grep abc|grep -v grep Both fairly returns the same result. For example, the process name is dynamic and we are having the process name in a variable, how we can apply the above trick. For example "a" is the... (11 Replies)
Discussion started by: pandeesh
11 Replies

5. Shell Programming and Scripting

-n option with grep command

Hi, what is the meaning of -n option before the grep command ? grep command searches for the specified string in the file tmp_crontab.txt but what does -n mean ? With Regards (1 Reply)
Discussion started by: milink
1 Replies

6. Shell Programming and Scripting

Need best grep option or alternative

Hello, I am processing a text file which contains only words with few combination of characters (it is a dictionary file). example: havana have haven haven't havilland havoc Is there a way to exclude only 1 to 8 character long words which not include space or special characters : '-`~.. so... (5 Replies)
Discussion started by: alekkz
5 Replies

7. Shell Programming and Scripting

Alternative to grep

How to find a particular line in a file without using grep? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

8. Shell Programming and Scripting

--alternative option in getopt

Hi, i need to use --alternative option of getopt for ex . getopt -o a:c: --alternative pw: -- "$@" if i use like this, i am not getting any output.Please help me how to correct this.i need to have a combination of long and short options.But long options have to begin with - and not... (0 Replies)
Discussion started by: padmisri
0 Replies

9. UNIX for Dummies Questions & Answers

Grep alternative to handle large numbers of files

I am looking for a file with 'MCR0000000716214' in it. I tried the following command: grep MCR0000000716214 * The problem is that the folder I am searching in has over 87000 files and I am getting the following: bash: /bin/grep: Arg list too long Is there any command I can use that can... (6 Replies)
Discussion started by: runnerpaul
6 Replies
Login or Register to Ask a Question