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
OPENPAM_READLINE(3)					   BSD Library Functions Manual 				       OPENPAM_READLINE(3)

NAME
openpam_readline -- read a line from a file LIBRARY
Pluggable Authentication Module Library (libpam, -lpam) SYNOPSIS
#include <sys/types.h> #include <security/pam_appl.h> #include <security/openpam.h> char * openpam_readline(FILE *f, int *lineno, size_t *lenp); DESCRIPTION
The openpam_readline function reads a line from a file, and returns it in a NUL-terminated buffer allocated with malloc(3). The openpam_readline function performs a certain amount of processing on the data it reads. Comments (introduced by a hash sign) are stripped, as is leading and trailing whitespace. Any amount of linear whitespace is collapsed to a single space. Blank lines are ignored. If a line ends in a backslash, the backslash is stripped and the next line is appended. If lineno is not NULL, the integer variable it points to is incremented every time a newline character is read. If lenp is not NULL, the length of the line (not including the terminating NUL character) is stored in the variable it points to. The caller is responsible for releasing the returned buffer by passing it to free(3). RETURN VALUES
The openpam_readline function returns NULL on failure. SEE ALSO
free(3), malloc(3), pam(3) STANDARDS
The openpam_readline function is an OpenPAM extension. AUTHORS
The openpam_readline function and this manual page were developed for the FreeBSD Project by ThinkSec AS and Network Associates Laboratories, the Security Research Division of Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 (``CBOSS''), as part of the DARPA CHATS research program. BSD
December 21, 2007 BSD
All times are GMT -4. The time now is 07:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy