Visit The New, Modern Unix Linux Community


How to capture only some part of output when command executed??


 
Thread Tools Search this Thread
Operating Systems Solaris How to capture only some part of output when command executed??
# 1  
How to capture only some part of output when command executed??

Hi,

When I execute this command
prtdiag -v

output sample :
System clock frequency: 160 MHZ
Memory size: 4GB

==================================== CPUs ====================================
E$ CPU CPU
CPU Freq Size Implementation Mask Status Location
--- -------- ---------- --------------------- ----- ------ --------
0 1280 MHz 1MB SUNW,UltraSPARC-IIIi 2.4 on-line MB/P0
1 1280 MHz 1MB SUNW,UltraSPARC-IIIi 2.4 on-line MB/P1

================================= IO Devices =================================
Bus Freq Slot + Name +
Type MHz Status Path Model
------ ---- ---------- ---------------------------- --------------------
pci 66 MB pci108e,1648 (network)
okay /pci@1f,700000/network@2

pci 66 MB pci108e,1648 (network)
okay /pci@1f,700000/network


But I want only CPU count i.e 0 and 1 from above output.
How can I parse the output for only CPU column in shell script?
# 2  
use the "psrinfo" command...
# 3  
are you looking for something like this ?

Code:
prtdiag -v | grep -A3 'CPU' # print three lines After the pattern matched.

# 4  
Quote:
Originally Posted by thegeek
are you looking for something like this ?

Code:
prtdiag -v | grep -A3 'CPU' # print three lines After the pattern matched.

but what if you have 4 cpus or 8 or 64?
# 5  
Try:
Code:
prtdiag -v | awk '/^CPU/,/^=/ { if($0 ~ /^[0-9]+/) print; }' | wc -l

or

Code:
prtconf | grep -c cpu


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #76
Difficulty: Easy
Richard Stallman's GNU project was also started in response to AT&T's increasingly restrictive Unix software licensing terms.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Python Paramiko multi threading to capture all output for command applied in loop

My issue : I am getting only last command output data in ouput file. Though comamnd "print(output)" displays data for all 3rd column values but the data saved in file is not what required it hs to be the same which is being printed by command"print(output)". Could you please help me to fix this,... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

3. UNIX for Dummies Questions & Answers

Set Command to output a log of every command executed in the script

Hi Guys, I like to output every command executed in the script to a file. I have tried set -x which does the same. But it is not giving the logs of the child script which is being called from my script. Is there any parameters in the Set command or someother way where i can see the log... (2 Replies)
Discussion started by: mac4rfree
2 Replies

4. HP-UX

How capture all user command line output?

Hi I want to know how capture all user command line output and save this commands and outputs to text files? if you have script for this subject please give me.:o please help me thank you (6 Replies)
Discussion started by: amvhd
6 Replies

5. Shell Programming and Scripting

Capture output of command triggered in background

Is there any way to trigger a sequence of commands in parallel and capture their output in variables? e.g. something on the following lines x=`echo "X" &` y=`echo "Y" &` z=`echo "Z" &` so that $x, $y, and $z evaluate to X, Y and Z res. (7 Replies)
Discussion started by: jawsnnn
7 Replies

6. Solaris

How to capture Output of truus command

Hi I want to check if some process is sleeping. I can see that in truss -p <pid> I want to capture output and check that output if proces sis sleeping. Please suggest way to capture output of truss command or other way to check if process is sleeping (1 Reply)
Discussion started by: ankush_mehra
1 Replies

7. Shell Programming and Scripting

Enter the command to capture output--help

&& echo "PLEASE enter the command to capture output" || echo "Processing your command manual" x=$# echo $x while do while man $@ | read -r line do >$@.txt ... (1 Reply)
Discussion started by: rrd1986
1 Replies

8. Shell Programming and Scripting

How do I capture multiple lines of the status output of a command?

I need to know what the upload speed of an Internet connection. I thought the easiest way to do this would be to transfer a file via FTP to my server using the command: sh-3.2$ ftp -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded Note: My environment allows me to issue... (2 Replies)
Discussion started by: zzz1528
2 Replies

9. Shell Programming and Scripting

Set specific part in command output into variable

I am trying unsuccessfully to set into a variable a specific part of command output: The command output will be as: line 1: <varied> line 2: 2 options: option 1: Set view: ** NONE ** or option 2: Set view: <different_name_of_views_always_without_spaces> and I would like to get into... (7 Replies)
Discussion started by: orit
7 Replies

10. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies

Featured Tech Videos