First occurence from grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers First occurence from grep
# 8  
Old 08-23-2007
Code:
awk '/search_pattern/{print;exit}' file

# 9  
Old 08-23-2007
Quote:
Originally Posted by namishtiwari
Hi,
I tried both the options and it gave me errors.I am doing this in solaris machine.Is that can be an issue to succesfull execute this command.

grep namish test8 |{ read;echo "$REPLY";}
read: missing arguments
$ grep namish test8 | { read;echo "$REPLY"; }
read: missing arguments
$ { read;echo "$REPLY";}< <( grep namish test8 )
syntax error: `<' unexpected
[...]
So you're using sh(/bin/sh or /usr/bin/sh) on Solaris,
in that case you have to pass a name for the variable:

Code:
grep namish test8 |{ read v;echo "$v";}

I'd use another shell (bash/dtksh/zsh ...).
# 10  
Old 08-23-2007
MySQL

Thanks radoulove,
that is working perfectlly fine.

Thanks,
Namish
# 11  
Old 08-23-2007
Quote:
Originally Posted by sriram003
uniq filename

This will remove the duplicates.
Sriram,
Without understanding the problem please do not suggest anything and if want to give any suggestion stick to the problem.
anyway thaks for two wonderfull answers you gave.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. UNIX for Dummies Questions & Answers

grep the last occurence

is there a grep or awk one-line command to print the line of the last occurence of a string in a file? (3 Replies)
Discussion started by: apalex
3 Replies

10. 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
Login or Register to Ask a Question