Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    5

    Unanswered: Unix Commands Help

    Hi

    I am female/25/london. I was wondering if any sweet guys out there could help me describe thefollowing script fragments.



    1) sed -e s/$*/[WORDS DELETED]/g

    2) sed -e "s/$</[WORDS DELETED]/g"

    3). kill -9 $$

    4) set file=$1
    shift
    set cmd=sed
    foreach n ( 1 2 3 4 5 6 7 8 9 )
    if ( $n <= $#argv ) then
    set cmd="${cmd} -e s/"\$"$n/$argv[$n]/g"
    endif
    end
    csh -c "${cmd}" < $file


    Please reply soon

    Love Lisa xxx
    *mwuah*

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Have you read man pages for this commands ?
    Jean-Pierre.

  3. #3
    Join Date
    Mar 2004
    Posts
    5
    Yes I have but cant figure out what exactly those fragments do. have an idea but i don't think it's right

    could use your help darlin.

    Love Lisa
    xxx

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    1) in a script or function, substitute the string which value is all arguments, by '[WORDS DELETED]' from stdin, the result is written to stdout.

    In fact, for sed the first argument of the s command is a regular expression not a fixed string.

    If there are more than one argument, $* contains a space; since the substute command s/.../.../g ins not enclosed in quotes, sed will failed with syntax error message.

    2) I don't know the $< variable, maybe shell specific, it doesn't exist for sh or ksh

    3) it is a suicide, you kill your process ($$ is the current process id)

    4) build and execute a sed command that will substitutes in the file specified as first argument the strings $1 $2 ... by the values specified after the file name

    the_script input_file val_1 val2 val3
    => substitutes in file input_file "$1" by val_1, "$2" by val_2 and "$3" by val_3
    Jean-Pierre.

  5. #5
    Join Date
    Mar 2004
    Posts
    5
    Hi


    Thanks darlin for the reply.....but i am bit confused on some parts of it still:

    For the frist part sed- e is a stream editor and s replaces $* by WORDS DELETED (but what i am not sure about g)

    For the third part what does -9 mean?


    Can you explain a bit more clearly on the fourth part please


    Thanks hon.

    Love Lisa xxx

  6. #6
    Join Date
    Mar 2004
    Posts
    3
    The 'g' at the end of the sed commands means that the replacement (in this case, you can use this option with most commands) is to occur globally, and not just the first occurrance of the substitution.

    The -9 on the kill command pretty much ensures that the process will be killed. It does get more technical than that, but I don't know what specifically it does.

    I'll take a stab at the fourth part, but I could be a bit off as I don't normally get to do anything quite that complex.

    It looks like the command line for the script would be something like

    script file_name arg1 arg2 arg3 ...

    The first thing that it does is it takes $1 (file_name) and assigns it to the file variable. The shift causes all of the other arguments to move up in the chain of arguments. I.e., initially, file_name is $1, arg1 is $2, arg2 is $3 and so on. The only problem is that the for loop runs from 1 to 9, and you can't have a $10. So, to get around this, you shift. Then, arg1 is $1, arg2 is $2, arg3 is $3 and so on.

    The foreach loop runs allows you to run through those 9 arguments. The $#argv is the number of arguments that was passed to the script (NOTE I do not know if the shift command effects $#argv or not. Perhaps someone wiser and more knowledgable than I would know). So, the If statement says that if $n is less than the total number of arguments, the cmd variable is set to what ever cmd is currently set too, plus your regular expression that gets passed to sed. From my example above, the first time through (n==1), you'd see

    sed -e s/$1/arg1/g

    If you have say just 2 arguments, it would then go through a second time and set cmd to

    sed -e s/$1/arg1/g -e s/$2/arg2/g

    and so on until it finally gets to be $n > $#argv.

    Then, of course, it kicks the command off in a separate c shell and makes all of the changes to the file that was supplied on the original command line.

    Hope that answers your questions without being too wordy (which I tend to get sometimes).

    Hobbletoe
    Last edited by Hobbletoe; 03-31-04 at 12:53.

  7. #7
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    Are you really a girl?

  8. #8
    Join Date
    Feb 2004
    Posts
    143
    Or maybe not. As her name itself suggests (the game), maybe
    it is really a girl game ( lol' )

  9. #9
    Join Date
    Mar 2004
    Posts
    5
    Jean-Pierre.

    I can you get back to me on the unix commands help as well the one i posted on 03-30-04 14:20 .....pretty plzzz



    Love Always Lisa xxx

  10. #10
    Join Date
    Mar 2004
    Posts
    5

    Cool

    Well of course i am and thats what the guys tell me when they see the insides!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •