How can I just grep one instance of a word in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can I just grep one instance of a word in the file
# 1  
Old 06-18-2012
How can I just grep one instance of a word in the file

I want to grep some information out of the dmidecode but when I type

Code:
dmidecode | grep Memory

I get several instances of the word. Is there a way I can just choose which instance I want to display?
# 2  
Old 06-18-2012
How do you decide which instance of "Memory" you want? You must have criteria to do this.

Please show us what those criteria are.
# 3  
Old 06-18-2012
Code:
sudo dmidecode | grep Manufacturer
	Manufacturer: Hewlett-Packard
	Manufacturer: Hewlett-Packard
	Manufacturer: Hewlett-Packard
	String 5: String5 for Original Equipment Manufacturer
	Option 1: String1 for Type12 Equipment Manufacturer
	Option 2: String2 for Type12 Equipment Manufacturer
	Option 3: String3 for Type12 Equipment Manufacturer
	Option 4: String4 for Type12 Equipment Manufacturer
	Manufacturer: OEM_Define2
	Manufacturer: AD00000000000000
	Manufacturer: AD00000000000000
	Manufacturer: Intel(R) Corporation

I just want the first instance to show up
# 4  
Old 06-18-2012
use the head command

append
Code:
| head -1

to the end of any command, and you will get only the first line.
# 5  
Old 06-18-2012
Oh cool. Thats badass thanks, what if I only wanted the 4 instance. Already tried | head -4 and that displayed 4 instances and not just the forth.
# 6  
Old 06-18-2012
then...

Code:
| head -4 | tail -1

# 7  
Old 06-18-2012
Code:
dmidecode | awk '++s[Manufacturer] == 4'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to Grep second word in config file using parameter?

Currently i am building one script to grep region records in the config file based on parameter and then i am creating a text file with that out put and i am reading the source file path in that out put file now i need to pass one more parameter like module based upon that it has to create a... (1 Reply)
Discussion started by: saranath
1 Replies

2. Shell Programming and Scripting

One instance of comparing grep and awk

Hi. In thread https://www.unix.com/shell-programming-and-scripting/267833-grouping-counting.html rovf and I had a mini-discussion on grep and awk. Here is a demo script that compares the awk and grep approaches for this single problem: #!/usr/bin/env bash # @(#) s2 Demonstrate group... (1 Reply)
Discussion started by: drl
1 Replies

3. UNIX for Advanced & Expert Users

Grep the only instance name

Hi, I want to get the only application name from the server. Ex: if i give $ ps -ef | grep bw. It will show all BW process with entire path. It will little confuse to list out the process. Can anyone have syntax to get only the instance name. I need this for be, hawk,ems also. Please... (2 Replies)
Discussion started by: ckchelladurai
2 Replies

4. Shell Programming and Scripting

grep for a string until instance of a space

Hey guys, I'm having a bit of trouble getting this to work using either sed or grep. It's possible awk might be the ticket I need as well, but my regulat expression skills aren't quite up to the task for doing this. I'm looking to grep for the string ERROR from the following log up until any... (6 Replies)
Discussion started by: terrell
6 Replies

5. Shell Programming and Scripting

grep second instance of same string

Hi all, i am new to unix scripting in ksh or any shell for that matter. I have downloaded a xml file from a website and saved on my local harddrive. inside the xml, the same tag is listed multiple times. <title>Tonight</title> <title>Thursday</title> <title>Friday</title>... (6 Replies)
Discussion started by: scubasteve39
6 Replies

6. Shell Programming and Scripting

Search text file, then grep next instance of string

I need to be able to search for a beginning line header, then use grep or something else to get the very next instance of a particular string, which will ALWAYS be in "Line5". What I have is some data that appears like this: Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line1 Line2 ...... (4 Replies)
Discussion started by: Akilleez
4 Replies

7. Shell Programming and Scripting

Search for last instance of word in a file

Hi I'm trying to search for the last instance of the word 'cache' in a HTML file that I have downloaded from YouTube. I'm using the following syntax, but an error is thrown when I try it. grep -f "cache" Also I wish to append the above grep command to the below so that the search for cache... (3 Replies)
Discussion started by: colmbell
3 Replies

8. UNIX for Dummies Questions & Answers

Grep the word at the end of the file

I need to grep the word "hello" in each and every file. This word will be placed either at the end of the file or before the end of the file. Ex: file1: file2: afdsaf dsfalk fdsa weruoi sdaf erwqiuo fsdaf ... (5 Replies)
Discussion started by: sivakumar.rj
5 Replies

9. Shell Programming and Scripting

grep second word in a file

How do I match second word and then print that line to output For eg: My file has following text and I want to check if second word is n then I want to print entire line . xytxti8naclip y xytxt32bpsimple y xytxt32bpna n xytxti16nae y xysmps32bpp031_bst n... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

how to grep for a word in a log file..

Hi All, I have a log file which is storing a backup time stamps information in it. (pasted below) 20081006210008 0 20081006211910 20081006222824 0 20081006224758 20081007210049 0 ... (2 Replies)
Discussion started by: suri.tyson
2 Replies
Login or Register to Ask a Question