I want to grep some information out of the dmidecode but when I type
dmidecode | grep Memory
I get several instances of the word. Is there a way I can just choose which instance I want to display?
I want to grep some information out of the dmidecode but when I type
dmidecode | grep Memory
I get several instances of the word. Is there a way I can just choose which instance I want to display?
How do you decide which instance of "Memory" you want? You must have criteria to do this.
Please show us what those criteria are.
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
append
| head -1
to the end of any command, and you will get only the first line.
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.
| head -4 | tail -1
dmidecode | awk '++s[Manufacturer] == 4'
cool. linux is fun
---------- Post updated at 11:06 AM ---------- Previous update was at 11:05 AM ----------
one last grep question. How can I grep two words?
---------- Post updated at 11:09 AM ---------- Previous update was at 11:06 AM ----------
ok sorry that was a dumb question
Hi.
Matching occurrences:
#!/usr/bin/env bash
# @(#) s1 Demonstrate matching occurrences.
# See: http://sourceforge.net/projects/cgrep/
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C cgrep
FILE=${1-data1}
pl " Data file $FILE:"
head -10 $FILE
pl " Find all \"a\":"
cgrep a $FILE
pl " Omit first 2 \"a\":"
cgrep +N 2 a $FILE
pl " Omit first 2 \"a\", then match one:"
cgrep +N 2 -N 1 a $FILE
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
cgrep ATT cgrep 8.15
-----
Data file data1:
1 a
2 b
3 a
4 c
5 a
6 d
7 a
8 e
-----
Find all "a":
1 a
3 a
5 a
7 a
-----
Omit first 2 "a":
5 a
7 a
-----
Omit first 2 "a", then match one:
5 a
See link in script for access to cgrep
Best wishes ... cheers, drl