09-09-2009
find out line number of matching string using grep
Hi all,
I want to display line number for matching string in a file. can anyone please help me.
I used
grep -n "ABC" file
so it displays
6 ABC.
But i only want to have line number,i don't want that it should prefix matching context with line number.
Actually my original problem is that i want to use this number & used to print next line.
So can anyone please provide me code to first find out a particular pattern in file & displays the content of next line.
i used to print the content using sed -n '8p' file, if i have found the matching string on line 7.
Thanks in advance
sarbjit
Last edited by sarbjit; 09-09-2009 at 03:41 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Dear Masters,
Here i have some doubts can anyone clarify?.
Is it possible to grep the lines by specifying the line numbers.
I know the line number which i want to grep.
example:
grep 40th line filename
grep 50th line filename
Need ur comments. (4 Replies)
Discussion started by: salaathi
4 Replies
2. Shell Programming and Scripting
hi,
i have to grep for string in file but i want to find the group of this line so i must get lines before and select the group.
the file look like :
####name_groupe1
alphanumeric line
alphanumeric line
..
####name_groupe2
alphanumeric line
alphanumeric line
..
####name_groupe3... (4 Replies)
Discussion started by: kamel.seg
4 Replies
3. UNIX for Dummies Questions & Answers
Hi all,
I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like:
(echo "1.txt";echo "2.txt") | xargs zgrep -no STRING
If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies
4. Shell Programming and Scripting
Hi,I am new to shell scripting and i want to find the line numbers of matching braces.
The file contents are as follows
File XXX.dat
1 ( CLASS "FRUIT"
2 (TYPE "PERSISTENT")
3 (MESSAGE_TYPE "M")
4 (GET_REQRD "Y")
5 (SET_REQRD "Y")
6 )
7 ( CLASS... (3 Replies)
Discussion started by: Rajendra_1510
3 Replies
5. Shell Programming and Scripting
Hi All,
Please tell me how can I Find a string using grep & print the line above or below that in solaris?
Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies
6. Shell Programming and Scripting
Hi
I have requirement to find nth occurrence in a file and capture data from with in lines (between lines)
Data in File.
<QUOTE>
<SESSION>
<ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/>
<ATTRIBUTE NAME='Service Name' VALUE='None'/>
</SESSION>
<SESSION>
<ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies
7. Shell Programming and Scripting
Hi,
I have one input file with the following content:
MY_inpfile.txt
Aname1 Cname1 Cname2 1808 5
Aname2 Cname1 1802 47
Bname1 ? 1819 22
Bname2 Cname1 1784 11
Bname3 1817 9
Zname1 Cname1 1805 59
Zname2 Cname1 Cname2 Cname3 1797 27
Every line in my input file have a 4 digit... (5 Replies)
Discussion started by: Szaffy
5 Replies
8. Shell Programming and Scripting
I have a string
joe-dimech-varp123.23-drw.msf
peter-erch-varp2.23-drw.msf
pawlu-donje-seru-varp3123.23-drw.msf
I want to remove the entry containing the varp tag (The varp is followed by a number)
I want to get
joe-dimech-drw.msf
peter-erch--drw.msf
pawlu-donje-seru-drw.msf (3 Replies)
Discussion started by: kristinu
3 Replies
9. Shell Programming and Scripting
I have a simple text file having payment amount value on each line. At the end of day 'n' number of payments created difference in amount that I need to match from this file.
I have information about how many payments created difference and difference amount. Please help me to build shell... (3 Replies)
Discussion started by: swats007
3 Replies
10. Shell Programming and Scripting
Hi
I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field.
The source file is pipe delimited and looks something like
1|net|ABC Letr1|1530|||
1|net|EXP_1040 ABC|1121|||
1|net|EXP_TG1224|1122|||
1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies
LEARN ABOUT REDHAT
lsdiff
LSDIFF(1) LSDIFF(1)
NAME
lsdiff - show which files are modified by a patch
SYNOPSIS
lsdiff [-n] [-p n] [--strip=n] [--addprefix=PREFIX] [-s]
[-i PATTERN] [-x PATTERN] [-v] [file...]
lsdiff {--help | --version | --filter ... | --grep ...}
DESCRIPTION
List the files modified by a patch.
You can use both unified and context format diffs with this program.
OPTIONS
-n Display the line number that each patch begins at. If verbose output is requested, each hunk of each patch is listed as well.
For each file that is modified, a line is generated containing the line number of the beginning of the patch, followed by a Tab
character, followed by the name of the file that is modified. If -v is given, following each of these lines will be one line for
each hunk, consisting of a Tab character, the line number that the hunk begins at, another Tab character, the string ``Hunk #'', and
the hunk number (starting at 1).
-p n When matching, ignore the first n components of the pathname.
--strip=n
Remove the first n components of the pathname before displaying it.
--addprefix=PREFIX
Prefix the pathname with PREFIX before displaying it.
-s Show file additions, modifications and removals. A file addition is indicated by a ``+'', a removal by a ``-'', and a modification
by a ``!''.
-i PATTERN
Include only files matching PATTERN.
-x PATTERN
Exclude files matching PATTERN.
-v Verbose output.
--help Display a short usage message.
--version
Display the version number of lsdiff.
--filter
Behave like filterdiff(1) instead.
--grep Behave like grepdiff(1) instead.
SEE ALSO
filterdiff(1), grepdiff(1)
EXAMPLES
To sort the order of touched files in a patch, you can use:
lsdiff patch | sort -u |
xargs -rn1 filterdiff patch -i
To show only added files in a patch:
lsdiff -s patch | grep '^+' |
cut -c2- | xargs -rn1 filterdiff patch -i
To show the headers of all file hunks:
lsdiff -n patch | (while read n file
do sed -ne "$n,$(($n+1))p" patch
done)
AUTHOR
Tim Waugh <twaugh@redhat.com>.
patchutils 13 May 2002 LSDIFF(1)