Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to display particular line of the output. For eg, i executed "cat /proc/cpuinfo". The output is:
Quote:
[root@Ubuntu]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Core(TM)2 Duo CPU T5270 @ 1.40GHz
stepping : 13
cpu MHz : 800.000
cache size : 2048 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm ida
bogomips : 2791.74
clflush size : 64
I want to display CPU MHz alone. How to parse the Output? Here my CPU MHz is 800.00. I want to assign the value to a variable, say for eg. N, and write the value of N to a file named "cpu.txt". How to perform it? Thanks in advance.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329
Rep:
the simplest solution is the one you like the most, I believe.
An Awk guru would use the ghostdog snippet, a Perl monger would program something else (in perl, obviusly :-). I prefer shell scripting
@HasC: Most people tend to go with what they know (hence the cat file | awk 'something' | awk 'somethingelse' constructs, which can probably done with one awk statement).
I noticed over time that ghostdog74 likes resource friendly, elegant and precise coding (which is a good thing!) and I'm a bit confused why he posted that specific command. Especially because the output isn't fully correct.
errmm, because you posted this solution earlier than me that's why. As for the "complicated" version, i am being overly cautious, that's all. As for the output, changing -F":" to -F": " will correct that minor space problem.
Last edited by ghostdog74; 12-17-2009 at 06:45 AM.
BTW: The output of /proc/xyz is by convention (the describing part), no need to be overly cautious. But then again, conventions are broken all the time, so maybe it is a good idea to make it case insensitive.....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.