sed or awk scripting help needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed or awk scripting help needed
# 1  
Old 06-25-2009
Error 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% /export/home
/dev/mapper/vglocal-fisc
4128448 308516 3610220 8% /fisc
/dev/mapper/vglocal-backup
2064208 252008 1707344 13% /fisc/backup
/dev/mapper/vglocal-perf
4128448 1046068 2872668 27% /fisc/perf
/dev/mapper/vglocal-opt
2064208 2062405 1803 80% /opt
/dev/cciss/c0d0p7 2063504 456700 1501984 24% /var
/dev/mapper/vglocal-crash
17546044 77808 16576948 1% /var/crash
/dev/cciss/c0d0p2 17544368 77800 16575364 1% /var/diskdump
tmpfs 524288 523765 523 94% /tmp

I want to search for above 80% usage...
for the above example /tmp and /opt Filesystem are exceeding

i need to add a word "HI" before starting of the line and "BYE" after the line
in our case:
HI tmpfs 524288 523765 523 94% /tmp BYE

I'm new to sed scripting, anybody help is greatly appreciated
# 2  
Old 06-25-2009
Try...
Code:
awk '{s=substr($5,1,match($5,"%")-1)
if (s > 80)
   $0="Hi "$0" Bye"
   print
   }' inputfile

# 3  
Old 07-07-2009
Hi All

I want to show df -h, whichever F/S is 80% above i need to add "HI" at Starting of the Line and "BYE" at the ending of the line.

Example shown as below:

[itgcead7@lrtp68 cgi-bin]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/cciss/c0d0p6 3.0G 1.1G 1.8G 37% /
/dev/cciss/c0d0p1 251M 18M 221M 8% /boot
none 7.9G 0 7.9G 0% /dev/shm
/dev/mapper/vglocal-home
1008M 725M 233M 76% /export/home
/dev/mapper/vglocal-fisc
4.0G 2.0G 1.9G 52% /fisc
/dev/mapper/vglocal-backup
2.0G 266M 1.7G 14% /fisc/backup
/dev/mapper/vglocal-perf
4.0G 806M 3.0G 22% /fisc/perf
/dev/mapper/vglocal-opt
2.0G 153M 1.8G 8% /opt
/dev/cciss/c0d0p7 2.0G 297M 1.6G 16% /var
/dev/mapper/vglocal-crash
17G 76M 16G 1% /var/crash
/dev/cciss/c0d0p2 17G 76M 16G 1% /var/diskdump
HI tmpfs 512M 412M 101M 81% /tmp BYE
# 4  
Old 07-07-2009
Try this,

df -k | awk '$5 >= "70%" { printf "HI "; printf; printf " BYE"; printf "\n"; }'
# 5  
Old 07-07-2009
Quote:
Originally Posted by Ramesh_srk
Try this,

df -k | awk '$5 >= "70%" { printf "HI "; printf; printf " BYE"; printf "\n"; }'
I don't think you can compare it with %...
# 6  
Old 07-07-2009
I have checked in my server and its works fine!!
# 7  
Old 07-07-2009
Hi,

Try this.

894t005 $df -h |awk '$5>80{print "HI " $0 " BYE"}'|grep -v "Filesystem"HI /lib 9.8G 8.6G 1.1G 89% /lib BYE
HI /platform 9.8G 8.6G 1.1G 89% /platform BYE
HI /sbin 9.8G 8.6G 1.1G 89% /sbin BYE
HI /usr 9.8G 8.6G 1.1G 89% /usr BYE
HI /platform/SUNW,Sun-Fire-T200/lib/libc_psr/libc_psr_hwcap1.so.1 9.8G 8.6G 1.1G 89% /platform/sun4v/lib/libc_psr.so.1 BYE
HI /platform/SUNW,Sun-Fire-T200/lib/sparcv9/libc_psr/libc_psr_hwcap1.so.1 9.8G 8.6G 1.1G 89% /platform/sun4v/lib/sparcv9/libc_psr.so.1 BYE
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

help needed using awk scripting

Hi, I've few files in the following format file 1 ------------------------- A=a1 B=0 C=1 D=3 A=a2 B=0 C=1 D=3 A=a3 B=0 C=6 D=7 A=a4 B=0 C=1 D=3 A=a5 B=0 C=1 D=3 file 2 ------------------------- A=a1 B=2 C=2 D=4 A=a2 ... (2 Replies)
Discussion started by: skpvalvekar
2 Replies

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

5. Shell Programming and Scripting

sed/shell scripting - add line if needed and not allready there

I am writing a shell script that checks all .c files to see if they use fprintf or printf. If a file does, then the line #include <stdio.h> is added to the top of the file, unless it's already there. This is what I've got: #!/bin/sh egrep -l f?printf *.c | while read file; do sed -i '1i\... (2 Replies)
Discussion started by: computethis
2 Replies

6. Shell Programming and Scripting

awk or sed help needed

Hi All, p1=90; if then echo "<font color=red>" else echo "<font color=green>" fi how to i do it in awk or sed scripting ? (4 Replies)
Discussion started by: raghur77
4 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

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

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. Shell Programming and Scripting

scripting with awk and sed

hey all, i was just wondering if it was possible to to get data from user input , and parse it through sed to remove or add what that user has entered into a flat file? do i need awk ? any help is greatly appreciated ~shan2on (2 Replies)
Discussion started by: shan2on
2 Replies
Login or Register to Ask a Question