awk or sed help needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk or sed help needed
# 1  
Old 07-23-2009
Power awk or sed help needed

Hi All,

p1=90;

if [ $p1 > 70 ]
then
echo "<font color=red>"
else
echo "<font color=green>"
fi

how to i do it in awk or sed scripting ?
# 2  
Old 07-23-2009
what you want to do?
# 3  
Old 07-24-2009
hi

$ free
total used free shared buffers cached
Mem: 16438364 15336772 1101592 0 397540 9716872
-/+ buffers/cache: 5222360 11216004
Swap: 8385920 91088 8294832


total memory = 16438364 KB
used memory = 15336772 KB
free memory = 1101592 KB

used memory percentage = 93%.

Now I have to display if memory utilisation is more than 70% then i wanted to display free command in red color or else in green color in HTML PAGE.

p1=93;

if [ $p1 > 70 ]
then
echo "<font color=red> $(free) </font>"
else
echo "<font color=green>$(free)</font>"
fi

how to i do it in awk or sed scripting ?
# 4  
Old 07-24-2009
try the ff.
Code:
FGRED=`echo "\033[31m"`
FGCYAN=`echo "\033[36m"`
BGRED=`echo "\033[41m"`
FGBLUE=`echo "\033[35m"`
NORMAL=`echo "\033[m"`

source
# 5  
Old 07-24-2009
You can do something like that with awk :
Code:
free  | \
awk -v limit=70 -F'[ =%]' '
/used memory percentage/ {
   freemem = $(NF-1);
   color = (freemem > limit ? "red" : "green");
   sub($(NF-1) "%", "<font color=" color ">" $(NF-1) "</font>%")
} 
1 '

Output :
Code:
total used free shared buffers cached
Mem: 16438364 15336772 1101592 0 397540 9716872
-/+ buffers/cache: 5222360 11216004
Swap: 8385920 91088 8294832


total memory = 16438364 KB
used memory = 15336772 KB
free memory = 1101592 KB

used memory percentage = <font color=red>90</font>%.

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed with file output awk sed command - please

Hi I have a file that contains lines starting with a particular string plus a Colon: I need to output all these lines but only what comes after the colon Can you pelase assist? Example of lines in the file: com.ubs.f35.cashequities/cashequities: 1 2 ... (5 Replies)
Discussion started by: mnassiri
5 Replies

2. Shell Programming and Scripting

Most vexing: Sed or Awk scripting for date conversion needed

Hi, I have some files being sent to me that have dates in them in this format: from 1/8/2011 15:14:20 and I need the dates in this format (mysql date format) To 2011-01-08 15:14:20 all I have so far is the regexp that detects the format: sed -r -e 's@\1/\2/\3\4\5\6]::$@do... (7 Replies)
Discussion started by: Astrocloud
7 Replies

3. Shell Programming and Scripting

Formatting help needed awk or sed maybe

I am executing the following command: sort file1.txt | uniq -c | sort -n > file2.txt The problem is that in file 2, I get leading spaces, Like so: 1 N/A|A8MW11 8 N/A|ufwo1 9 N/A|a8mw11 10 900003|smoketest297688 10 N/A|a9dg4 10 danny|danni 12... (5 Replies)
Discussion started by: ddurden7
5 Replies

4. Shell Programming and Scripting

sed or awk help needed

hi all, tnsping DBNAME > out.txt cat out.txt TNS Ping Utility for Linux: Version 10.2.0.2.0 - Production on 23-JUL-2009 05:49:52 Copyright (c) 1997, 2005, Oracle. All rights reserved. Used parameter files: /fisc/oracle/product/10.2.0/network/admin/sqlnet.ora Used TNSNAMES adapter to... (2 Replies)
Discussion started by: raghur77
2 Replies

5. Shell Programming and Scripting

sed or awk scripting help needed

hi all, for an example : df -k output shows: $ df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/cciss/c0d0p6 3099260 1117760 1824068 8% / /dev/cciss/c0d0p1 256666 18065 225349 8% /boot none 8219180 0 8219180 0% /dev/shm /dev/mapper/vglocal-home 1032088 245172 734488 26%... (7 Replies)
Discussion started by: raghur77
7 Replies

6. Shell Programming and Scripting

Help needed with sed

Can someone please help me correctly frame the below sed command: sed 's/.*/$(date +%Y%m%d)' filepattern I have read a line of the file in filepattern variable which is like below: P.182.MKT_DISC.*.2_1_1.* I want to replace the last .* part with the current date in the format yyyymmdd.... (6 Replies)
Discussion started by: 100Rab
6 Replies

7. Shell Programming and Scripting

Sed/Awk Help needed

Hello All, Does anybody know how to extract the entries from the 1st and second column that match a multiple regex expression using either sed or awk? I have a 40 k file with the data that looks like this. 2 VZudbEE.ds_HP11i-726..> 2 VZudbEEE.ds_IB-726-5..> 2... (1 Reply)
Discussion started by: liketheshell
1 Replies

8. UNIX for Dummies Questions & Answers

SED Help Needed

I am trying to retrieve part of a line from /boot/grub/menu.lst The line is : gfxmenu (hd0,0)/usr/share/gfxboot/themes/pclinuxblue/boot/message I have figured out how to get this line into a file by itself. sed '/gfxmenu/ !d' /boot/grub/menu.lst > /tmp/menu.lst.pcl_tc What I need to... (2 Replies)
Discussion started by: Tide
2 Replies

9. Shell Programming and Scripting

AWK/SED Help needed

Hi, I'm new to Awk/Sed programming. I have a status file like this: TYPE | FILE1 | Now Started TYPE | FILE2 | Just Finished TYPE | FILE3 | Now Started TYPE | FILE4 | Just Finished For a given FILE no, I need to change the "Now Started" condition to "Just Finished" in this file. The... (5 Replies)
Discussion started by: autouser123
5 Replies

10. UNIX for Dummies Questions & Answers

Help needed with sed

Hi, I need to insert a line into a file underneath an existing line in the file, but am unsure as to the syntax. I'm pretty sure sed can be used though, although any ideas are more than welcome. For example: File ---- Line 1 Line 2 Line 3 Line 4 Line 6 I need to say: Insert "Line 5"... (1 Reply)
Discussion started by: danhodges99
1 Replies
Login or Register to Ask a Question