Sponsored Content
Full Discussion: shell fonction with sed
Top Forums Shell Programming and Scripting shell fonction with sed Post 302142385 by cfajohnson on Thursday 25th of October 2007 11:01:51 PM
Old 10-26-2007
Quote:
Originally Posted by moustik
Hi guys,

Newbe in scripting /bin/ksh I'm needing some help.
Working on : SunOS I386 Solaris5.10

Here is the idea:

I would like to create a function that will show only a part of the command df -h with sed.
The aim is to see only the disk name and the pourcentage of it. (eg"c0t0d0s0 / 70%")

In my full script I had the command and it's working well.
echo "toto" `df -h /|grep %| sed -e 's/[0-9].[0-9]G//g' -e 's/[0-9].[0-9]M//g' -e 's/[0-9]G//g' -e 's/[0-9]M//g' -e 's#/dev/dsk/#/#g'` "\n" >> $LOG &&

I would like to create a function that will take those command.

But I should have some mistakes Smilie in because i cannot make it work. Does someone have an idea? thank


Here is my script

#!/bin/ksh
#
DATE=`date '+%y%m%d%H%M'`
LOG=/var/log/autosed$DATE.log
export LOG
DEBUG=echo

#function that permit to sow a part of the df -h command.

call_sed()
{
sedcmd=`grep % | sed -e 's/[0-9].[0-9]G//g' -e 's/[0-9].[0-9]M//g' -e 's/[0-9]G//g' -e 's/[0-9]M//g' -e 's#/dev/dsk/#/#g'` >> $LOG
df -h $1 | $sedcmd
}
call_sed "/"

You are assigning the output of a command to $sedcmd instead of the command itself.

Don't make your script more complex than it need be:

Code:
call_sed()
{
  df -h $1 |
   grep % | sed -e 's/[0-9].[0-9]G//g' \
                -e 's/[0-9].[0-9]M//g' \
                -e 's/[0-9]G//g' \
                -e 's/[0-9]M//g' \
                -e 's#/dev/dsk/#/#g' >> "$LOG"
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command in c shell

Hi, To insert a single quote at the end of every line in a file , I do this: sed "s:$:':" temp.txt Works like a charm in k shell, but errors out in c shell. Any inputs what could be wrong here? Thanx (5 Replies)
Discussion started by: nattynatty
5 Replies

2. Shell Programming and Scripting

sed / shell - how to use $filename

I've forgotten how to use a filename parameter using sed inside a shell script. What I want to do is replace a string inside a file with the name of the file being processed. I think this should work .. for filename do sed -e "s/xxx/$filename/" ... ... done Thanks! Ps: ... (5 Replies)
Discussion started by: eadie
5 Replies

3. Shell Programming and Scripting

shell script by sed

Hey everybody I need some help on how to order the data in file such as a file have first name last name and city and i would like to order them to in the same order by using sed thanks alot for your time (6 Replies)
Discussion started by: halola85
6 Replies

4. UNIX for Dummies Questions & Answers

shell script - sed

Hi i have a problem how to put som lines on top or in the bottom of the text with sed. problem is that i am reading from stdin and when i have som lines starting with ++, i have to put some characters on the top of the lines starting with that ++ example of input oooo ++abcd ++befg... (1 Reply)
Discussion started by: Dun
1 Replies

5. Shell Programming and Scripting

shell program with sed

I want to substitute a charactor "PAN" with "TAN" in a shell, I used sed command in shell, it wo'nt work but the same is run from command prompt it was successful. the command is sed ' s/PAN/TAN/g ' <i/p> > <o/p> sed ' s/^M/^M/g ' <i/p> > <o/p> (1st ^M is Ctrl+V+M, 2nd should be line feed/next... (1 Reply)
Discussion started by: anil_kut
1 Replies

6. Shell Programming and Scripting

Help with shell script and sed!

Hi folks, maybe somebody here can help me. I have 2 files. File A and File B. File A contains URLs leading to files on the Internet, with one URL per line; The format of the URLs on each line in File A is . File B contains only the filenames from each line in File A; One filename per line. ... (11 Replies)
Discussion started by: o0110o
11 Replies

7. Shell Programming and Scripting

using sed in shell script

Hi all, I have files with the following names; afgcxa.pem4jan.rain.nc afgcxa.pem4feb.rain.nc afgcxa.pem4mar.rain.nc afgcxa.pem4apr.rain.nc I want to rename them to afgcxa.pem4-01.jan.rain.nc afgcxa.pem4-02.feb.rain.nc afgcxa.pem4-03.mar.rain.nc ... (5 Replies)
Discussion started by: Muhammad Rahiz
5 Replies

8. Shell Programming and Scripting

using sed in shell script

Hi, i want to replace sub text which is in the middle of long text. let me be more clear with an example. Here is the actual text in the xml file <module-option name="principalDNSuffix">,cn=Users,dc=X,dc=Y</module-option> Now, in the above text, i want to replace all the content lying... (3 Replies)
Discussion started by: sunrexstar
3 Replies

9. Shell Programming and Scripting

Shell Scripting -- sed

Hi, In one of my scripts, I am using sed to do an expression replacement. The code in the script is as under sed "s|MY_INP_Lab=""|MY_INP_Lab="${2}"|" file1, where $2=xyz_abc_mbk The EXPECTED output is in file1, all the instances ofMY_INP_Lab="" shall be replaced by... (2 Replies)
Discussion started by: vivekmattar
2 Replies

10. Shell Programming and Scripting

Need help on shell script (sed)

Hi Guys, I have a xml file as below where I need to find the particular XML tag(<dpath>) and delete the content of it. <?xml version="1.0" encoding="UTF-8"?> <title>XML</title><head>Ram</head><ControlCenter><doStatus>1</doStatus></ControlCenter><exitlabel>Gzip... (7 Replies)
Discussion started by: Vinoth Kumar G
7 Replies
suspend(1)                                                         User Commands                                                        suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 12:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy