Re: A SED script

2004-06-27 Thread antenneX
- Original Message - 
From: Malcolm Kay [EMAIL PROTECTED]
To: antenneX [EMAIL PROTECTED]; Giorgos Keramidas
[EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Saturday, June 26, 2004 10:35 PM
Subject: Re: A SED script


 On Sunday 27 June 2004 07:49, antenneX wrote:
  - Original Message -
  From: Giorgos Keramidas [EMAIL PROTECTED]
  To: antenneX [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Saturday, June 26, 2004 1:40 PM
  Subject: Re: A SED script
 
   On 2004-06-26 12:08, antenneX [EMAIL PROTECTED] wrote:
I cannot get it to work on another file (perl.pl file) to change
the
 
  line:
$OrderNumPrefix = ATX060; to $OrderNumPrefix = ATX070;
   
I suspect I'm not handling the quotes or other operators
correctly
 
  and it
 
just ignores the change.
   
Here's the snippet of the script I'm trying to use:
#!/bin/sh
new=`grep -i new /path/to/newfile`
old=`grep -i new /path/to/oldfile`

 It would seem that the variables new and old will both be set to
something
 containing 'new' (perhaps not in lower case).
 How does this relate to ATX060 and ATX070?

sed -i.bak -e s/$old/$new/ /path/to/myfile
  
   The results depend heavily on the existence and contents of the
two
 
  files
 
   named /path/to/{old,new}file.  I'm sure if you change the sed line
to:
  
   sed -i.bak -e 's/ATX060/ATX070/' /path/to/myfile
  
   it will all work fine.
 
  Indeed, this works fine. The old/new files are needed to set the
  varibles to hold the new number for the next time as this is run via
  cron.
 

 You've still not shown us the relevant lines of /path/to/newfile or
 /path/to/oldfile

  old = ATX060
  new = ATX070

 What are these? The contents of /path/to/{new,old}file?
 If so sed will be looking to change the string old = ATX060 to
 new = ATX070.

 Or do the files simply consist of
 ATX060
 and
 ATX070
 ?
 If so then grep is not the right command to load the variables old and
new.
 Try:
   new=`cat /path/to/newfile`
   old=`cat /path/to/oldfile`

 Malcolm


I've solved the script ptoblem with a verbose run of the script  it
told me exactly what was wrong -- the two varibles newfile  oldfile
were not defined properly.

Running this showed the error:
/bin/sh -xv ./myscript

Sorry I didn't think to do this in the first place.

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: A SED script

2004-06-26 Thread Giorgos Keramidas
On 2004-06-26 12:08, antenneX [EMAIL PROTECTED] wrote:
 I cannot get it to work on another file (perl.pl file) to change the line:
 $OrderNumPrefix = ATX060; to $OrderNumPrefix = ATX070;

 I suspect I'm not handling the quotes or other operators correctly and it
 just ignores the change.

 Here's the snippet of the script I'm trying to use:
 #!/bin/sh
 new=`grep -i new /path/to/newfile`
 old=`grep -i new /path/to/oldfile`
 sed -i.bak -e s/$old/$new/ /path/to/myfile

The results depend heavily on the existence and contents of the two files
named /path/to/{old,new}file.  I'm sure if you change the sed line to:

sed -i.bak -e 's/ATX060/ATX070/' /path/to/myfile

it will all work fine.

 What do I need to change to make it work???

Something within oldfile or newfile, is a far reaching guess.

- Giorgos

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: A SED script

2004-06-26 Thread Warren Block
On Sat, 26 Jun 2004, antenneX wrote:
Running FBSD-4.10
Below is a portion of a script that uses sed(1) to change a portion of a
line in a file. It works fone for that one.
However, I cannot get it to work on another file (perl.pl file) to
change the line:
$OrderNumPrefix = ATX060; to $OrderNumPrefix = ATX070;
I suspect I'm not handling the quotes or other operators correctly and
it just ignores the change.
Here's the snippet of the script I'm trying to use:
#!/bin/sh
new=`grep -i new /path/to/newfile`
old=`grep -i new /path/to/oldfile`
sed -i.bak -e s/$old/$new/ /path/to/myfile
and, again the line in the file:
$OrderNumPrefix = ATX060; ---line in the file to change
What do I need to change to make it work???
You don't show what changes you have made to the program.  A first guess 
is that you aren't escaping quotes.  If you insert an echo command 
before the sed command, you'll be able to see what is actually going on. 
You may get away with just changing the sed pattern delimiter, say to 
something like a % sign.

-Warren Block * Rapid City, South Dakota USA
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: A SED script

2004-06-26 Thread antenneX
- Original Message - 
From: Giorgos Keramidas [EMAIL PROTECTED]
To: antenneX [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Saturday, June 26, 2004 1:40 PM
Subject: Re: A SED script


 On 2004-06-26 12:08, antenneX [EMAIL PROTECTED] wrote:
  I cannot get it to work on another file (perl.pl file) to change the
line:
  $OrderNumPrefix = ATX060; to $OrderNumPrefix = ATX070;
 
  I suspect I'm not handling the quotes or other operators correctly
and it
  just ignores the change.
 
  Here's the snippet of the script I'm trying to use:
  #!/bin/sh
  new=`grep -i new /path/to/newfile`
  old=`grep -i new /path/to/oldfile`
  sed -i.bak -e s/$old/$new/ /path/to/myfile

 The results depend heavily on the existence and contents of the two
files
 named /path/to/{old,new}file.  I'm sure if you change the sed line to:

 sed -i.bak -e 's/ATX060/ATX070/' /path/to/myfile

 it will all work fine.


Indeed, this works fine. The old/new files are needed to set the
varibles to hold the new number for the next time as this is run via
cron.

old = ATX060
new = ATX070

then, after the script changes the line in the perl script, it needs
to pipe (echo/cat) in the new file contents to the old:
cat newfile  oldfile --- which is now ATX070 for oldfile
...then incremement the newfile to become ATX080 and so on

Now, got to figure out how to increment number up. It is an invoice
prefix number that contains the month # and must modify the perl file
that is part of a custom order set of scripts.

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: A SED script

2004-06-26 Thread Malcolm Kay
On Sunday 27 June 2004 07:49, antenneX wrote:
 - Original Message -
 From: Giorgos Keramidas [EMAIL PROTECTED]
 To: antenneX [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Saturday, June 26, 2004 1:40 PM
 Subject: Re: A SED script

  On 2004-06-26 12:08, antenneX [EMAIL PROTECTED] wrote:
   I cannot get it to work on another file (perl.pl file) to change the

 line:
   $OrderNumPrefix = ATX060; to $OrderNumPrefix = ATX070;
  
   I suspect I'm not handling the quotes or other operators correctly

 and it

   just ignores the change.
  
   Here's the snippet of the script I'm trying to use:
   #!/bin/sh
   new=`grep -i new /path/to/newfile`
   old=`grep -i new /path/to/oldfile`

It would seem that the variables new and old will both be set to something
containing 'new' (perhaps not in lower case).
How does this relate to ATX060 and ATX070?

   sed -i.bak -e s/$old/$new/ /path/to/myfile
 
  The results depend heavily on the existence and contents of the two

 files

  named /path/to/{old,new}file.  I'm sure if you change the sed line to:
 
  sed -i.bak -e 's/ATX060/ATX070/' /path/to/myfile
 
  it will all work fine.

 Indeed, this works fine. The old/new files are needed to set the
 varibles to hold the new number for the next time as this is run via
 cron.


You've still not shown us the relevant lines of /path/to/newfile or
/path/to/oldfile

 old = ATX060
 new = ATX070

What are these? The contents of /path/to/{new,old}file?
If so sed will be looking to change the string old = ATX060 to
new = ATX070.

Or do the files simply consist of
ATX060
and
ATX070
?
If so then grep is not the right command to load the variables old and new.
Try:
  new=`cat /path/to/newfile`
  old=`cat /path/to/oldfile`

Malcolm


 then, after the script changes the line in the perl script, it needs
 to pipe (echo/cat) in the new file contents to the old:
 cat newfile  oldfile --- which is now ATX070 for oldfile
 ...then incremement the newfile to become ATX080 and so on

 Now, got to figure out how to increment number up. It is an invoice
 prefix number that contains the month # and must modify the perl file
 that is part of a custom order set of scripts.

 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to
 [EMAIL PROTECTED]

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]