If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Unix Commands Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-04, 14:03
thegame thegame is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
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*
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 00:20
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Have you read man pages for this commands ?
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-30-04, 07:34
thegame thegame is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 03-30-04, 08:32
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
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.
Reply With Quote
  #5 (permalink)  
Old 03-30-04, 10:20
thegame thegame is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 03-30-04, 12:34
Hobbletoe Hobbletoe is offline
Registered User
 
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 11:53.
Reply With Quote
  #7 (permalink)  
Old 03-30-04, 13:43
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Are you really a girl?
Reply With Quote
  #8 (permalink)  
Old 03-30-04, 16:42
saccskiz saccskiz is offline
Registered User
 
Join Date: Feb 2004
Posts: 143
Or maybe not. As her name itself suggests (the game), maybe
it is really a girl game ( lol' )
Reply With Quote
  #9 (permalink)  
Old 04-01-04, 05:48
thegame thegame is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 04-04-04, 10:19
thegame thegame is offline
Registered User
 
Join Date: Mar 2004
Posts: 5
Cool

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On