LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 01: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, 02:00 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
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, 02:06 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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, 07: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 11:44 AM
Sed & Awk hinetvenkat Linux - Software 4 05-30-2005 05:10 AM
Tutorial on sed & awk LinuxTiro Programming 4 11-10-2003 03:53 AM
printf new_user10 Programming 3 09-09-2003 11:12 PM
How is 'man 3 printf' different from 'man printf' ?? purpleburple Linux - General 3 09-23-2002 12:29 AM

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

All times are GMT -5. The time now is 08:51 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
Open Source Consulting | Domain Registration