Sponsored Content
Operating Systems Solaris How to find egrep version on Solaris 10 Post 94933 by zazzybob on Wednesday 4th of January 2006 11:12:44 PM
Old 01-05-2006
Code:
-bash-3.00$ ./kiran.sh ab 0 0 ./testfile
abc
abc
abc
-bash-3.00$ ./kiran.sh ab 0 2 ./testfile
abc
1
2
abc
1
2
abc
.
!
-bash-3.00$
-bash-3.00$ cat ./kiran.sh
#!/bin/ksh
# no -C option to grep? no fear...
# usage:
#   scriptname "searchterm" lines_before lines_after inputfile

matchstring="$1"
lines_before="$2"
lines_after="$3"
matchfile="$4"

matches=`echo "${line}" | egrep -n "${matchstring}" ${matchfile}`
if [ "$?" -ne "0" ]; then
   echo "No match" >&2
   exit 1
fi
echo "${matches} " | while read line; do
   lineno=`echo "${line}" | cut -d: -f1`
   match=`echo "${line}" | cut -d: -f2`
#  echo "Match found - line ${lineno} - ${match}"
   minline=$(( lineno - ${lines_before} ))
   [[ "$(( lineno - ${lines_before} ))" -lt 1 ]] && minline=1
   [[ "${lines_before}" -gt "0" ]] && \
   sed -n "$minline,$(( lineno - 1 ))p" ${matchfile}
   sed -n "$lineno p" ${matchfile}
   [[ "${lines_after}" -gt "0" ]] && \
   sed -n "$(( lineno + 1 )),$(( lineno + ${lines_after} ))p" ${matchfile}
done

exit 0

So for your requirements

scriptname "searchterm" 0 <trailing_lines> filename

Cheers
ZB
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I find Unix Version

I am extremely new here. Someone wants to upgrade off of Unix to Windows 2000 and wants to know if they need to buy new hardware How do I find out what type of Unix they're using? How do I find out the current hardware of the system? (Intel, ..etc) Thanks (3 Replies)
Discussion started by: tomsha
3 Replies

2. UNIX for Dummies Questions & Answers

How do I find out what version of X I'm using?

How can I find out? Besides looking on the box of my distro and checking their. (2 Replies)
Discussion started by: DISTURBED
2 Replies

3. UNIX for Dummies Questions & Answers

Find Software Version

Hi, Is there anyway to find what version of a software is installed on a particular box ? For Tru64 unix, the setld -i command lists all the software that is installed. But how do i get the version ? is there a unix command for this? Is setld specific to Tru64 ? Do reply VJ (1 Reply)
Discussion started by: vjsony
1 Replies

4. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

5. Solaris

what is the command to see the java version in solaris 8 and solaris 10

what is the command to see the java version in solaris 8 and solaris 10 (1 Reply)
Discussion started by: tv.praveenkumar
1 Replies

6. Shell Programming and Scripting

egrep help required to find pattern

Hi All, Can some one please help me how to grep the comments from "oracle" & "sybase" code. I would like to grep below type of pattern. -- /* */ Please help. (6 Replies)
Discussion started by: gr8_usk
6 Replies

7. Shell Programming and Scripting

Egrep ERE to find null

Hello All, My apologies if a similar question has already been posted. I searched for "grep", "egrep" and "null" I'm having an issue with egrep and an extended regular expression. I'm doing a test for a job name. I would like to have the user enter a job name with no spaces and also test to... (7 Replies)
Discussion started by: sydox
7 Replies

8. Solaris

How to read this Solaris version:-Solaris 8 HW 5/03 s28s_hw2wos_06a SPARC?

Hi Guys, Could you please tell me how to read this Solaris version:- Solaris 8 HW 5/03 s28s_hw2wos_06a SPARC Thanks. (3 Replies)
Discussion started by: manalisharmabe
3 Replies

9. Shell Programming and Scripting

Egrep on Solaris

how can I implement egrep -A 1 "(HI|FR|GO|TAT)" in solaris? (5 Replies)
Discussion started by: aydj
5 Replies

10. UNIX for Beginners Questions & Answers

Egrep find word that occurs twice in a row

Hi there I am trying to figure out and understand what the syntax would be to egrep lines that have a word occur twice in a row. the two words obviously should have a space between them and also it has to be case sensitive which I believe grep is by deffault. the closest I have come is... grep... (7 Replies)
Discussion started by: spo_2138
7 Replies
NNGRAB(1)						      General Commands Manual							 NNGRAB(1)

NAME
nngrab - news retrieval by keyword (nn) SYNOPSIS
nngrab [ -c ] keyword DESCRIPTION
nngrab invokes nn on all USENET articles whose subject (or keyword) field(s) contain an instance of keyword. nngrab is a fast equivalent for: nn -mxX -s/keyword all For example, nngrab tesla will retrieve items concerning Nikola Tesla. Keyword case is ignored unless -c is specified, and the keyword can be a regular expressions (escaped to avoid conflicts with the shell). For example, nngrab "n.*tesla" The range of search includes all newsgroups on the system, including ones which are unsubscribed. FILES
$db/subjects subject database SEE ALSO
nn(1), nnspew(8), egrep(1) NOTES
nngrab can be much faster than the equivalent command shown above, if the tertiary news subject database generated by the nnspew(8) daemon exists. To enable the faster operation, nnspew must be executed regularly by cron. nngrab uses egrep(1) to scan the subject database, so if you are not running fast egrep (GNU-style) this is all for naught. nngrab will use a subject database generated by nnspew independent of its age. Thus, if you stop running nnspew, remember to remove the subjects file as well. BUGS
Under version 6.4 onwards, search of the "Keywords:" field is not supported. Search on name is not possible either. AUTHOR
James A. Woods, NASA Ames Research Center E-mail: jaw@ames.arc.nasa.gov 4th Berkeley Distribution Release 6.6 NNGRAB(1)
All times are GMT -4. The time now is 10:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy