Sponsored Content
Full Discussion: awk or sed help needed
Top Forums Shell Programming and Scripting awk or sed help needed Post 302337369 by aigles on Friday 24th of July 2009 03:09:56 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 08:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy