LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2004, 02:51 PM   #1
rickenbacherus
Member
 
Registered: Mar 2003
Location: colorado springs. colorado
Distribution: Debian-Sid 2.6.24-rt1
Posts: 290

Rep: Reputation: 30
need help w/ awk & printf


This very simple script works fine:
Code:
echo -n "Kernel:" 
uname -a|awk '{print $1, $3}'
echo -n "CPU:"
cat /proc/cpuinfo|grep name|awk '{print $4, $5, $6, $7}'
cat /proc/cpuinfo|grep MHz|awk '{print $2, $3, $4}'
echo -n "Mem/Use:" && free|grep Mem:|awk '{print $2, $3}' && echo -n "Uptime:"
uptime|awk '{print $3}'
echo -n "Resolution:"
When executed prints this:

Kernel:Linux 2.6.5
CPU:AMD Athlon(TM) XP 2200+
MHz : 1795.664
Mem/Use:1002320 188820
Uptime:5:41


I would however like to change the format so that it looks like this:

Kernel:Linux 2.6.5 CPU:AMD Athlon(TM) XP 2200+ @ 1795.664 MHz
Mem/Use:1002320 188820 Uptime:5:41

So far I have only managed to make the format extremely ugly.
Thanks alot for any pointers!
 
Old 05-11-2004, 03:00 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
It works with backticks:
Code:
echo "Kernel: `uname -a|awk '{print $1, $3}'` CPU: `cat /proc/cpuinfo|grep name|awk '{print $4, $5, $6, $7}'` @ `cat /proc/cpuinfo|grep MHz|awk '{print $4" "$2}'`"
echo "Mem/Use: `free|grep Mem:|awk '{print $2, $3}'` Uptime: `uptime|awk '{print $3}'`"
or perhaps easier to read:
Code:
echo -n "Kernel: `uname -a|awk '{print $1, $3}'`"
echo -n " CPU: `cat /proc/cpuinfo|grep name|awk '{print $4, $5, $6, $7}'`"
echo " @ `cat /proc/cpuinfo|grep MHz|awk '{print $4" "$2}'`"
echo -n "Mem/Use: `free|grep Mem:|awk '{print $2, $3}'`"
echo " Uptime: `uptime|awk '{print $3}'`"
 
Old 05-11-2004, 03:06 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Code:
#!/bin/bash

KERNEL=$(uname -a|awk '{print $1, $3}')
CPU=$(cat /proc/cpuinfo|grep name|awk '{print $4, $5, $6, $7}')
CLK=$(cat /proc/cpuinfo | awk -F': ' '/MHz/{print $2}')
MEM=$(free|grep Mem:|awk '{print $2, $3}')
UPTIME=$(uptime|awk '{print $3}')

echo "Kernel:$KERNEL CPU:$CPU@ $CLK MHz" 
echo "Mem/Use:$MEM Uptime:$UPTIME"
 
Old 05-13-2004, 08:21 AM   #4
rickenbacherus
Member
 
Registered: Mar 2003
Location: colorado springs. colorado
Distribution: Debian-Sid 2.6.24-rt1
Posts: 290

Original Poster
Rep: Reputation: 30
Perfect! Thanks alot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed/awk for matching & substituition laikos Programming 3 11-22-2006 12:44 PM
Sed & Awk hinetvenkat Linux - Software 4 05-30-2005 06:10 AM
Tutorial on sed & awk LinuxTiro Programming 4 11-10-2003 04:53 AM
printf new_user10 Programming 3 09-10-2003 12:12 AM
How is 'man 3 printf' different from 'man printf' ?? purpleburple Linux - General 3 09-23-2002 01:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration