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!
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.
I want to display particular line of the output. For eg, i executed "cat /proc/cpuinfo". The output is:
[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.
@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.....