Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to: Grep certain info from HWinfo Post 302684573 by bakunin on Thursday 9th of August 2012 06:29:35 PM
Old 08-09-2012
"grep" will not help you (at least not "grep" alone), because grep filters lines with some patterns in it from a text - nothing less, nothing more. It can either display these filtered lines or count them, but that's it.

But as luck will have it, there are more tools in the Unix toolbox than just "grep" and solving your problem is easy:

Code:
OEM id: "DELL"
Product: "PowerEdge 850"
Serial: "5GTKL94"

In this case you have to filter certain parts of the lines. You can use sed, awk or similar tools for this, but i prefer pure shell code, as this runs by far fastest (i simulate your utility by a simple "cat" and a here-document, which will give the output. Replace this with your original command):

Code:
(cat <<EOF
OEM id: "DELL"
Product: "PowerEdge 850"
Serial: "5GTKL94"
EOF) |\
while read LINE ; do
     LINE="${LINE#*\"}"     # chop off everything up to the first double quote
     LINE="${LINE%\"*}"     # chop off everything after the last double quote
     print - "$LINE"
done

The CPU count is a little more tricky, because you have to sum. Use "awk" for such things:

Code:
(cat <<EOF
cpu cores : 4
cpu cores : 4
cpu cores : 4
cpu cores : 4
EOF) |\
awk 'BEGIN {sum=0;} {sum+=$4;} END {printf( "%2d\n", sum);}'

The next is a combination of line filter and cutting some text from the line. You can use "sed" for such things:

Code:
(cat <<EOF
If possible display RAM as GB (8 GB)
MemTotal: 8185084 kB
EOF) |\
sed -n 's/^MemTotal: //p'

The last one is of the same form (line filter plus text cutting), hence the same approach:

Code:
(cat <<EOF
Filesystem Size Used Avail Use% Mounted on
/dev/md0 72G 63G 9.2G 88% /
EOF) |\
sed '1d;s/^.[^ ]* //;s/ .*$//'


To get the number of hdisks is a problem without knowing which hdisks you have: IDE disks are usually named differently than SCSI (SAS) disks, LUNs using one of the many FC-technologies (SDD, Multipath, Powerpath, and so on) often have even several names for the same disk (each way to the fabric gets its own name), etc..

Tell us, which disks you have or expect and we can tell you how to scan for these.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SU info

from the man page of su: EXAMPLES Example 1: Becoming User bin While Retaining Your Previously Exported Environment To become user bin while retaining your previously exported environment, execute: example% su bin Example 2: Becoming User bin and ... (4 Replies)
Discussion started by: afflack
4 Replies

2. UNIX for Dummies Questions & Answers

Grep Info

What is NR this statement grep '^\{1,10\}$' $colfile | awk '{print "my_col_id("NR") := "$2";"}' >> $SQL_TEMP_FIL Thanks Pinky (1 Reply)
Discussion started by: pinky
1 Replies

3. Shell Programming and Scripting

Need Info

Hi, I'm a oracle DBA with little knowledge of Unix. I wanted to write some shell scripts which will be helpful for DBA's regular activity. As i'm a new to oracle with unix can any plese tell me what are all the activities can be done throgh Unix Shell Scripts also suggest me how to learn... (1 Reply)
Discussion started by: msgobinathan
1 Replies

4. UNIX for Dummies Questions & Answers

Some Info.

Hiya all ... i am a newbie to UNIX, Just want to knwo what this command does: /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}' I think, 'grep shows the line with 'inet addr' (which is the 2nd line, displaying the IP Address, Broadcast Address and Subnet Mask) ... Is... (8 Replies)
Discussion started by: ad4m88
8 Replies

5. Shell Programming and Scripting

Getting LV Info

I have this working ksh, and it returns like below: LOGICAL VOLUME: prod_2048_005 VOLUME GROUP: prod1vg TYPE: raw WRITE VERIFY: off PHYSICAL VOLUME: hdisk108 VOLUME GROUP: prod1vg TOTAL PPs: 1023 (130944 megabytes) VG DESCRIPTORS: 1 USED PPs: 904 (115712 megabytes) MAX REQUEST: 1 megabyte... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

6. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

7. Shell Programming and Scripting

How to pull info under headers in file(awk,grep,while loop)

below is an extract from my file and I am trying to use Awk and grep and a while loop to pull infomation from under neath "HBA WWN=".HBA WWN=" reoccurs all over the file but the 100000c.....number are unique and I want to be able to pull and reference specifi information under this header ever time... (2 Replies)
Discussion started by: kieranfoley
2 Replies

8. Shell Programming and Scripting

need a one liner to grep a group info from /etc/group and use that result to search passwd file

/etc/group tiadm::345:mk789,po312,jo343,ju454,ko453,yx879,iy345,hn453 bin::2:root,daemon sys::3:root,bin,adm adm::4:root,daemon uucp::5:root /etc/passwd mk789:x:234:1::/export/home/dummy:/bin/sh po312:x:234:1::/export/home/dummy:/bin/sh ju454:x:234:1::/export/home/dummy:/bin/sh... (6 Replies)
Discussion started by: chidori
6 Replies

9. Shell Programming and Scripting

Grep/awk part of info of a column

I have a question that I am at a loss to solve. I have 3 column tab-separated data, such as: abs nmod+n+n-commitment-n 349.200023 abs nmod+n+n-a-commitment-n 333.306429 abs into+ns-j+vn-pass-rb-divide-v 295.57316 abs nmod+n+ns-commitment-n 182.085018 abs nmod+n+n-pledge-n ... (2 Replies)
Discussion started by: owwow14
2 Replies

10. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
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 03:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy