Sponsored Content
Full Discussion: grep the last occurence
Top Forums UNIX for Dummies Questions & Answers grep the last occurence Post 19987 by apalex on Thursday 18th of April 2002 05:00:38 PM
Old 04-18-2002
i think

#grep "string" file | tail -1

will do? or is there any better way? i just thought i don't want to grep the whole file, especially if its a huge file...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep for certain occurence

I am using grep to pull out info from a file. The line I am searching for begins: START TIME - Tue Sep 11 16:40:00. There are mutiple lines of START TIME. I need the FIRST occurence ONLY. My grep is as follows: start="$( grep 'START TIME' filename | cut -c15-33)" If I echo or cat... (2 Replies)
Discussion started by: app4dxh
2 Replies

2. UNIX for Advanced & Expert Users

First Occurence

Hi, This is the format of the file that i have StartDate:10/01/06 EndDate :10/02/06 Cno Ccode 1 10 2 11 StartDate:10/03/06 EndDate :10/04/06 Cno Ccode 2 13 4 12 StartDate:10/01/06 EndDate :10/02/06 (5 Replies)
Discussion started by: kkm_job
5 Replies

3. Shell Programming and Scripting

Extracting the last occurence

Hi All, Is there any awk or unix command that i can make use such that the output will be as desired ? The code will extract the latest pattern starting from the term above the asterix till the end of the input Input: ******** aaa bbb 2007 ******** 123 234 134 ******** xxx yyy 2007... (9 Replies)
Discussion started by: Raynon
9 Replies

4. UNIX for Dummies Questions & Answers

First occurence from grep

Hi , supoose i have a file in which a word is repeated so many times. I just want the firts occurence of that word through grep and it should not go to the next one means get the first occurence and stop there. Suggest me some solutions. Thanks Namish (10 Replies)
Discussion started by: namishtiwari
10 Replies

5. UNIX for Dummies Questions & Answers

grep the number of first occurence

File1.txt ....... ....... OMC LA OMC LK OMC LS ........ ........ Above is the content of File1.txt, i want to get the Number of Occurence to order, lets say if OMC LA = 1, OMC LS=3, and OMC LK=2.. omc_ident="OMC LA" or "OMC LK" or "OMC LS" omc_num=`grep '^OMC' File1.txt| grep... (4 Replies)
Discussion started by: neruppu
4 Replies

6. UNIX for Dummies Questions & Answers

number of occurence using grep -c then assigning it to a variable

Hi guys! I need to count the occurence of a certain pattern. For example the pattern is PC. the contents of the file sample.txt: A PC asdfgadfjkl asdfa PC sadfaf fdsPCasdfg if i use grep -c PC sample.txt it will display 3 as the number of occurence how do i save that number to a... (1 Reply)
Discussion started by: khestoi
1 Replies

7. Shell Programming and Scripting

Is there a way to grep the first occurence after a grep?

I have a text file: firstname: John lastname: Jay age: 33 firstname: Amy lastname: Jay age: 12 firstname: Max lastname: Jay age: 50 Currently I have first=`grep firstname file.txt | head -1` age=`grep -A 2 $name file.txt | tail -1` (7 Replies)
Discussion started by: etranman1
7 Replies

8. Shell Programming and Scripting

Percentage of occurence

Dear all, I have data like below and i need to add coloumn before the COUNT field to see the Percentage out of all COUNT field value for respective raw. ============================================= COUNT CODE sConnType tConnType... (6 Replies)
Discussion started by: Iroshan
6 Replies

9. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

10. Shell Programming and Scripting

Regex to match only first occurence with grep

Hello to all, How would be the correct regex to match only the first occurence of the pattern 3.*6. I'm trying with 3.*6 trying to match only 34rrte56, but with my current regex is matching 4rrte567890123456789123powiluur56. And if I try with ? doesn't print anything echo... (6 Replies)
Discussion started by: Ophiuchus
6 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 08:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy