Re: [CentOS] script help

2009-06-18 Thread Mfawa Alfred Onen
Dear Chloe,
  John Doe`s script is a good start, even though it will work for single
words space separated. The LINE Variable only passes the Arguments as single
words to ($1 and $2 respectively). I will also work on something for you
too...

On Thu, Jun 18, 2009 at 10:34 AM, John Doe  wrote:

>
> From: chloe K 
> > I have a file. list.txt (two columns)
> >
> > column1column2
> > nameaddress
> >
> > I need to put in the letter file letter.txt eg:
> >
> > Dear: Chloe
> > Address: CA
> >
> > Can I use this
> >
> > for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
>
> For single words space separated:
>
>  cat list.txt | while read LINE
>do
>  set $LINE
>  printf "Dear: %s\nAddress: %s\n" $1 $2 >> $1.letter.txt
>done
>
> JD
>
>
>
>
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-18 Thread John Doe

From: chloe K 
> I have a file. list.txt (two columns)
>  
> column1column2
> nameaddress
>  
> I need to put in the letter file letter.txt eg:
>  
> Dear: Chloe
> Address: CA
>  
> Can I use this 
>  
> for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt

For single words space separated:

  cat list.txt | while read LINE
do
  set $LINE
  printf "Dear: %s\nAddress: %s\n" $1 $2 >> $1.letter.txt
done

JD


  

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-18 Thread Mohan

Hi

If your file has only 2 columns and there is no space exists in 2nd 
column then you can use this script


#!/bin/sh
FILE="list.txt"
OUTPUT="out.txt"
while read VAL

do
VAL1=$(echo $VAL | awk '{print $1}' )
VAL2=$(echo $VAL | awk '{print $2}' )

echo "DEAR: $VAL1" >> $OUPUT
echo "DEAR: $VAL2" >> $OUPUT
echo " ">> $OUTPUT

done<$FILE

if you have spaces in between your 2nd column you might have to format 
the file using awk/sed

so that there would be a valid delimeter between column1 and column2

column 1| column2 here we can use '|' as the delimeter and change awk 
statement

to awk -F '| ' '{print $1}' or something like this.

--
Regards,
Mohan.



chloe K wrote:

Hi
 
I have a file. list.txt (two columns)
 
column1column2

nameaddress
 
 
I need to put in the letter file letter.txt eg:
 
Dear: Chloe

Address: CA
 
Can I use this
 
for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
 
Thank you for your help
 
 
 
 
 




Looking for the perfect gift?* Give the gift of Flickr!* 




___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
  
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread Les Mikesell
chloe K wrote:
> Hi
> 
> I have a file. list.txt (two columns)
> 
> column1column2 nameaddress
> 
> 
> I need to put in the letter file letter.txt eg:
> 
> Dear: Chloe Address: CA
> 
> Can I use this
> 
> for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
> 
> Thank you for your help
> 

#!/bin/sh
while read NAME ADDRESS
do
sed -e"s/Chloe/$NAME/" -e"s/CA/$ADDRESS/" $NAME.letter.txt
done http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread Julian Thomas
On Wed, 17 Jun 2009 11:16:58 -0700 MHR wrote:
>
>
>I've never seen any shell or sed syntax that allows you to subscript a
>line like this.  You should read up on awk, although there is no
>simple way to do dual file processing along these lines.

Easy way to do this with awk is to have the first part of the script use awk to 
get the name and address. and then 
use them as arguments to a second invocation of awk.
-- 
 Julian Thomas:   j...@jt-mj.nethttp://jt-mj.net
 In the beautiful Genesee Valley of Western New York State!
 -- --
 You will always be lucky if you know how to make friends with strange cats.
 - Colonial American proverb


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread Filipe Brandenburger
Hi Chloe,

Please start by reading this:
http://www.catb.org/~esr/faqs/smart-questions.html

On Wed, Jun 17, 2009 at 13:54, chloe K wrote:
> I have a file. list.txt (two columns)

Separated by what? Tabs? Spaces? Can the fields themselves have spaces
in them? Do you have many records, one per row? Please give a more
informative example of the file you have...

> I need to put in the letter file letter.txt eg:
>
> Dear: Chloe
> Address: CA

Is that supposed to be a template? What are you trying to achieve?
Replace "Chloe" with the first field and "CA" with the second field of
the list.txt file? Create one file per row of list.txt?

If you ask vague questions all you will have are vague answers...

HTH,
Filipe
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread Mfawa Alfred Onen
There is going to be a problem with your sed line as the semi-column is not
helping matters. You can try using a database for easy retrieval with your
script. I hope it puts you on the way.

On Wed, Jun 17, 2009 at 7:16 PM, Brian  wrote:

> > Can I use this
> >
> > for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
> >
>
> Why don't you just try it and see if it works?
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread MHR
On Wed, Jun 17, 2009 at 11:16 AM, Brian wrote:
>> Can I use this
>>
>> for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
>>
>
> Why don't you just try it and see if it works?

There _is_ that, but it won't

:-)

mhr
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread MHR
On Wed, Jun 17, 2009 at 10:54 AM, chloe K wrote:
> Hi
>
> I have a file. list.txt (two columns)
>
> column1    column2
> name    address
>
> I need to put in the letter file letter.txt eg:
>
> Dear: Chloe
> Address: CA
>
> Can I use this
>
> for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
>

I've never seen any shell or sed syntax that allows you to subscript a
line like this.  You should read up on awk, although there is no
simple way to do dual file processing along these lines.  (An awk
script for this would need to know it has two files to process and
read in the first one, then print it with replacements from the second
one.)

Also, if the above were to work, it would be "for i in `cat" - the
"in" is part of "for" syntax

Man pages are really handy for this sort of thing

HTH

mhr
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2009-06-17 Thread Brian
> Can I use this
>
> for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
>

Why don't you just try it and see if it works?
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] script help

2009-06-17 Thread chloe K
Hi
 
I have a file. list.txt (two columns)
 
column1    column2
name    address
 
 
I need to put in the letter file letter.txt eg:
 
Dear: Chloe
Address: CA
 
Can I use this 
 
for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt
 
Thank you for your help
 
 
 
 
 


  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread William L. Maltby

On Mon, 2009-06-08 at 08:01 -0400, William L. Maltby wrote:
> 
> 2. Inside that, use the set command to change the field separator to "."
> 
Correction: IFS (the Interfield Separator) is just another variable.
Just regular assignment will set it.

-- 
Bill


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread William L. Maltby

On Mon, 2009-06-08 at 10:29 +0100, Tom Brown wrote:
> Hi
> 
> I need some logic to work out a value for me - this value is _always_ 
> the 3rd last field in a string seperated by '.' but the string could be 
> 5 or 6 fields long, e.g
> 
> foo.bar.VALUE.baz.lala
> 
> foor.bar.gigi.VALUE.baz.lala
> 
> I need to find VALUE - if this were python or something i could do it 
> but this has to be in shell -
> 
> Any clues?

Without trying to make code this early in the A.M., I'll give an
algorithm that will work entirely in shell. Then the man page should
give the details.

1. Make a subshell, either as a separate file or inline using
braces-type stuff
2. Inside that, use the set command to change the field separator to "."
3. Use the set command with the string use wish to parse. This sets each
field into $1, $2, ...
4. Alternate algorithm # 1
   Use the shell variable $# (IIRC) to see how many you have.
   Use the shell's math capabilities to calculate the variable number
 you want
   Use the shell to generate a command (eval, backslashes, ...) to
 reference that variable
5. Alternate algorithm # 2
   do a while loop until $# = 3 (if it's already <= to 3, next is
 skipped
   shift
   access $1
6. Alternate algorithm # 3
   If $# > 3
 use shell math ability to calculate how many shifts needed
 use shift with that number as parameter
   access $1
> 
> thanks
> 

HTH
-- 
Bill

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Stephen Harris
On Mon, Jun 08, 2009 at 10:56:09AM +0100, Tom Brown wrote:
> 
> >echo foo.bar.VALUE.baz.lala | awk -F. '{ print $(NF-2); }'
> 
> excellent - just what i needed


awk is probably the most readable way.  In traditional shell stuff like
this used to be done in awk or sed
  awk -F. '{print $(NF-2)}'
  sed -n 's/^.*\.\([^\.]*\)\.[^\.]*\.[^\.]*$/\1/p'

Now you _can_ do it totally inside a modern shell in a variety of ways.
Here are three options (tested with ksh93; _should_ work in bash, but
not tested)

1) Use IFS to split the string

 a=foo.var.VALUE.baz.lala
 OIFS="$IFS"
 IFS="."
 set -- $a
 IFS="$OIFS"
 shift $#-3
 echo $1
  
2) variation using arrays

 a=foo.var.VALUE.baz.lala
 OIFS="$IFS"
 IFS="."
 set -A A -- $a
 IFS="$OIFS"
 let x=${#A[*]}-3
 echo ${A[$x]}
  
3) Using string pattern matching

 a=foo.var.VALUE.baz.lala
 front=${a%.*.*.*}
 b=${a#$front.}
 b=${b%%.*}
 echo $b
  
-- 

rgds
Stephen
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Tom Brown

>echo foo.bar.VALUE.baz.lala | awk -F. '{ print $(NF-2); }'
>
>   

excellent - just what i needed

thanks
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Mogens Kjaer
muhammad panji wrote:
...
> awk -F\. {'print $3'}
> awk -F\. {'print $5'}
> awk -F\. {'print $6'}

awk -F\. {'print $(NF-2)'}

Mogens
-- 
Mogens Kjaer, Carlsberg A/S, Computer Department
Gamle Carlsberg Vej 10, DK-2500 Valby, Denmark
Phone: +45 33 27 53 25, Mobile: +45 22 12 53 25
Email: m...@crc.dk Homepage: http://www.crc.dk
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Tom Brown

> I am pretty sure there is a way in awk to figure out how many fields
> you have, then take the total # of fields -3 each time to get the
> third last one.  Just heading out the door and off hand can't remember
> how it would be done.
>
>   

i can do it in cheetah templating with

set myloc = $getVar("hostname","")split('.')[-3]

the -3 says the last 3rd field in the string - i need the same so maybe 
awk can do this
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Alex S.
Hi.

   echo foo.bar.VALUE.baz.lala | awk -F. '{ print $(NF-2); }'

-- 
Alex S.



On 08.06.2009 13:29, Tom Brown wrote:
> Hi
>
> I need some logic to work out a value for me - this value is _always_
> the 3rd last field in a string seperated by '.' but the string could be
> 5 or 6 fields long, e.g
>
> foo.bar.VALUE.baz.lala
>
> foor.bar.gigi.VALUE.baz.lala
>
> I need to find VALUE - if this were python or something i could do it
> but this has to be in shell -
>
> Any clues?
>
> thanks
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Jacques B.
On Mon, Jun 8, 2009 at 5:29 AM, Tom Brown wrote:
> Hi
>
> I need some logic to work out a value for me - this value is _always_
> the 3rd last field in a string seperated by '.' but the string could be
> 5 or 6 fields long, e.g
>
> foo.bar.VALUE.baz.lala
>
> foor.bar.gigi.VALUE.baz.lala
>
> I need to find VALUE - if this were python or something i could do it
> but this has to be in shell -
>
> Any clues?
>
> thanks
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>

I am pretty sure there is a way in awk to figure out how many fields
you have, then take the total # of fields -3 each time to get the
third last one.  Just heading out the door and off hand can't remember
how it would be done.

Jacques B.
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread James Bensley
Is there anyway you can tell which field it will be in (i.e. to use as
a search clause, so "search for the field with X properties"?)

Ultimately to get the data in the X'th field you are going to need
either awk or sed (they can both easily do this, awk probably easier
than sed)

You need to work out how you will know which field it will be in i.e.
the first, second, third? My shell scripting is rubbish but I would
guess it would go something like;

myString = "first.second.VALUE.fourth.fith"

awk -F\. {'print 3'} myString

This would print the third field seperated by a '.' (full stop/period)
of myString

That's a rubbishy wild stab in the dark as im rubbish at shell scripting.

I would actually bet money I have made things more complex hahahah!

Sorry, i tried :'(

James.

-BEGIN GEEK CODE BLOCK-
  Version: 3.1
GIT/MU/U dpu s: a--> C++>$ U+> L++> B-> P+> E?> W+++>$ N K W++ O M++>$ V-
PS+++ PE++ Y+ PGP t 5 X+ R- tv+ b+> DI D+++ G+ e(+) h--(++) r++ z++
--END GEEK CODE BLOCK--
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread Ralph Angenendt
michael.ket...@rm-solutions.de wrote:
> Sehr geehrte Damen und Herren, 
> 
> ich bin ab dem 15.06.2009 wieder zurück im Büro.
> Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
> [simon.schilli...@rm-solutions.de]
> 
> Viele Grüße,
> Michael Kettel

You can resubcribe then, when you are back. Please do not use
autoresponders if you do not know how they work.

No regards,

Ralph


pgp6bs1DJZG73.pgp
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread muhammad panji
On Mon, Jun 8, 2009 at 4:29 PM, Tom Brown wrote:
> Hi
>
> I need some logic to work out a value for me - this value is _always_
> the 3rd last field in a string seperated by '.' but the string could be
> 5 or 6 fields long, e.g
>
> foo.bar.VALUE.baz.lala
>
> foor.bar.gigi.VALUE.baz.lala
>
> I need to find VALUE - if this were python or something i could do it
> but this has to be in shell -


awk -F\. {'print $3'}
awk -F\. {'print $5'}
awk -F\. {'print $6'}



-- 
Muhammad Panji
http://sumodirjo.wordpress.com
http://www.kurungsiku.web.id
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help - '3rd last field'

2009-06-08 Thread michael . kettel
Sehr geehrte Damen und Herren, 

ich bin ab dem 15.06.2009 wieder zurück im Büro.
Bitte wenden Sie sich in dringenden Fällen an Simon Schillings 
[simon.schilli...@rm-solutions.de]

Viele Grüße,
Michael Kettel


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] script help - '3rd last field'

2009-06-08 Thread Tom Brown
Hi

I need some logic to work out a value for me - this value is _always_ 
the 3rd last field in a string seperated by '.' but the string could be 
5 or 6 fields long, e.g

foo.bar.VALUE.baz.lala

foor.bar.gigi.VALUE.baz.lala

I need to find VALUE - if this were python or something i could do it 
but this has to be in shell -

Any clues?

thanks
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


RE: [CentOS] script help

2007-11-02 Thread Ross S. W. Walker
Michael D. Kralka wrote:
> 
> Ross S. W. Walker wrote:
> > 
> > Try:
> > 
> > # find  -type d -name dir-192.168.\* -exec mv \{\} `echo
> > \{\} | sed 's/192\.168\./10\.0\./'` \;
> > 
> > That should recursively rename all directories from one 
> naming scheme to
> > another.
> 
> ... except for the fact that the `echo \{\} ...` will be evaluated by
> the shell and not find, so this is the same as:
> 
> find  -type d -name dir-192.168.\* -exec mv \{\} \{\} \;
> 
> Not very useful ;)

Yes, thanks for pointing that out, it would have to be put into a
loop then.

# for dir in `find  -type d -name dir-192.168.\* -print`; do
# mv $dir `echo $dir | sed 's/192\.168\./10\.0\./'`
# done

I also just saw the earlier post on the 'rename' command which does it
all for the OP and should be a lot faster then a shell script.

-Ross

__
This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread Toby Bluhm

[EMAIL PROTECTED] wrote:





Was there an problem with Frank's response from earlier?

rename 192.168 10.0 dir*
  


Bah! It's too simple!  :-)

--
Toby Bluhm
Midwest Instruments Inc.
30825 Aurora Road Suite 100
Solon Ohio 44139
440-424-2240


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread Ross S. W. Walker

Try:

# find  -type d -name dir-192.168.\* -exec mv \{\} `echo \{\} | sed 
's/192\.168\./10\.0\./'` \;

That should recursively rename all directories from one naming scheme to 
another.

-Ross


-Original Message-
From: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
To: CentOS mailing list 
Sent: Fri Nov 02 09:28:45 2007
Subject: Re: [CentOS] script help

I run it but it has error. 

sed 's/^dir-192\.168/dir-10\.0/'`
sed: read error on dir-192.168.0.31: Is a directory



--- Toby Bluhm <[EMAIL PROTECTED]> wrote:

> Toby Bluhm wrote:
> > adrian kok wrote:
> >> Hi Phil
> >>
> >> thank you
> >>
> >> But I have several hundred those pattern
> directories!
> >>
> >> I did think to cat those directories in a file
> >> "olddir"
> >>
> >> eg:
> >>
> >> dir-192.168.30.0   dir-192.168.30.144
> dir-192.168.30.184
> >> 
> >>
> >> and sed 's/dir-192.168/dir-10.0/g' olddir >
> newdir
> >>
> >> but i don't know how to move
> >> rename the directories in olddir to newdir
> >>
> >> Thank you again
> >>
> >>
> >>   
> >
> > Assuming dir-192.168*  are all in one directory
> level, cd to that dir:
> >
> > for olddir in `ls -1 | grep dir-192.168`
> > do
> > newdir=`echo $olddir | sed
> 's/^dir-192.168/dir-10.0/'`
> > mv $olddir $newdir
> > done
> >
> >
> 
>  That sed line should be: 
> 's/^dir-192\.168/dir-10\.0/'`
> 
> 
> -- 
> Toby Bluhm
> Midwest Instruments Inc.
> 30825 Aurora Road Suite 100
> Solon Ohio 44139
> 440-424-2240
> 
> 
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
> 


Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

__
This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


RE: [CentOS] script help

2007-11-02 Thread mike.redan
> 
> I run it but it has error. 
> 
> sed 's/^dir-192\.168/dir-10\.0/'`
> sed: read error on dir-192.168.0.31: Is a directory
> 


Was there an problem with Frank's response from earlier?

rename 192.168 10.0 dir*

It is a nice simple solution. You don't have to loop, or use extra
commands, just copy and paste that one command to your machine, and all
directories will be renamed. I just did it on 1000 directories, and it
took 0.052 seconds:

[EMAIL PROTECTED] test]$ ls -ld dir-192.168.0.* | wc -l
1000
[EMAIL PROTECTED] test]$ time rename 192.168 10.0 dir*


real0m0.052s
user0m0.012s
sys 0m0.040s
[EMAIL PROTECTED] test]$ ls -ld dir-10.0.0.* | wc -l
1000

Mike
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread Michael D. Kralka
Ross S. W. Walker wrote:
> 
> Try:
> 
> # find  -type d -name dir-192.168.\* -exec mv \{\} `echo
> \{\} | sed 's/192\.168\./10\.0\./'` \;
> 
> That should recursively rename all directories from one naming scheme to
> another.

... except for the fact that the `echo \{\} ...` will be evaluated by
the shell and not find, so this is the same as:

find  -type d -name dir-192.168.\* -exec mv \{\} \{\} \;

Not very useful ;)

Cheers,
Michael
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread adrian kok
I run it but it has error. 

sed 's/^dir-192\.168/dir-10\.0/'`
sed: read error on dir-192.168.0.31: Is a directory



--- Toby Bluhm <[EMAIL PROTECTED]> wrote:

> Toby Bluhm wrote:
> > adrian kok wrote:
> >> Hi Phil
> >>
> >> thank you
> >>
> >> But I have several hundred those pattern
> directories!
> >>
> >> I did think to cat those directories in a file
> >> "olddir"
> >>
> >> eg:
> >>
> >> dir-192.168.30.0   dir-192.168.30.144
> dir-192.168.30.184
> >> 
> >>
> >> and sed 's/dir-192.168/dir-10.0/g' olddir >
> newdir
> >>
> >> but i don't know how to move
> >> rename the directories in olddir to newdir
> >>
> >> Thank you again
> >>
> >>
> >>   
> >
> > Assuming dir-192.168*  are all in one directory
> level, cd to that dir:
> >
> > for olddir in `ls -1 | grep dir-192.168`
> > do
> > newdir=`echo $olddir | sed
> 's/^dir-192.168/dir-10.0/'`
> > mv $olddir $newdir
> > done
> >
> >
> 
>  That sed line should be: 
> 's/^dir-192\.168/dir-10\.0/'`
> 
> 
> -- 
> Toby Bluhm
> Midwest Instruments Inc.
> 30825 Aurora Road Suite 100
> Solon Ohio 44139
> 440-424-2240
> 
> 
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
> 


Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread Toby Bluhm

Toby Bluhm wrote:

adrian kok wrote:

Hi Phil

thank you

But I have several hundred those pattern directories!

I did think to cat those directories in a file
"olddir"

eg:

dir-192.168.30.0   dir-192.168.30.144 dir-192.168.30.184


and sed 's/dir-192.168/dir-10.0/g' olddir > newdir

but i don't know how to move
rename the directories in olddir to newdir

Thank you again


  


Assuming dir-192.168*  are all in one directory level, cd to that dir:

for olddir in `ls -1 | grep dir-192.168`
do
newdir=`echo $olddir | sed 's/^dir-192.168/dir-10.0/'`
mv $olddir $newdir
done




That sed line should be:  's/^dir-192\.168/dir-10\.0/'`


--
Toby Bluhm
Midwest Instruments Inc.
30825 Aurora Road Suite 100
Solon Ohio 44139
440-424-2240


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-02 Thread Toby Bluhm

adrian kok wrote:

Hi Phil

thank you

But I have several hundred those pattern directories!

I did think to cat those directories in a file
"olddir"

eg:

dir-192.168.30.0   
dir-192.168.30.144 
dir-192.168.30.184



and sed 's/dir-192.168/dir-10.0/g' olddir > newdir

but i don't know how to move 


rename the directories in olddir to newdir

Thank you again


  


Assuming dir-192.168*  are all in one directory level, cd to that dir:

for olddir in `ls -1 | grep dir-192.168`
do
newdir=`echo $olddir | sed 's/^dir-192.168/dir-10.0/'`
mv $olddir $newdir
done


--
Toby Bluhm
Midwest Instruments Inc.
30825 Aurora Road Suite 100
Solon Ohio 44139
440-424-2240


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-01 Thread Frank Cox
On Fri, 02 Nov 2007 03:18:35 +0800 (CST)
adrian kok <[EMAIL PROTECTED]> wrote:

> But I have several hundred those pattern directories!

What's wrong with the rename command?

-- 
MELVILLE THEATRE ~ Melville Sask ~ http://www.melvilletheatre.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-01 Thread adrian kok
Hi Phil

thank you

But I have several hundred those pattern directories!

I did think to cat those directories in a file
"olddir"

eg:

dir-192.168.30.0   
dir-192.168.30.144 
dir-192.168.30.184


and sed 's/dir-192.168/dir-10.0/g' olddir > newdir

but i don't know how to move 

rename the directories in olddir to newdir

Thank you again



--- Phil Schaffner <[EMAIL PROTECTED]>
wrote:

> On Fri, 2007-11-02 at 02:22 +0800, adrian kok wrote:
> > Hi all 
> > 
> > how can I have script to rename the following
> > directory pattern from
> > 
> >  
> > 
> > from 
> > 
> > dir-192.168.30.0   
> > dir-192.168.30.144 
> > dir-192.168.30.184
> > 
> > 
> > To:
> > 
> > 
> > dir-10.0.30.0   
> > dir-10.0.30.144 
> > dir-10.0.30.184
> 
> If you are just renaming directories, or files, and
> not files in
> directories, the following should work:
> 
> for i in 0 144 184 ; do mv dir-192.168.30.$i
> dir-10.0.30.$i ; done
> 
> Or in a bit prettier form:
> 
> for i in 0 144 184
> do
>   mv dir-192.168.30.$i dir-10.0.30.$i
> done
> 
> 
> Phil
> 
> 
> ___
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
> 


Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-01 Thread Phil Schaffner
On Fri, 2007-11-02 at 02:22 +0800, adrian kok wrote:
> Hi all 
> 
> how can I have script to rename the following
> directory pattern from
> 
>  
> 
> from 
> 
> dir-192.168.30.0   
> dir-192.168.30.144 
> dir-192.168.30.184
> 
> 
> To:
> 
> 
> dir-10.0.30.0   
> dir-10.0.30.144 
> dir-10.0.30.184

If you are just renaming directories, or files, and not files in
directories, the following should work:

for i in 0 144 184 ; do mv dir-192.168.30.$i dir-10.0.30.$i ; done

Or in a bit prettier form:

for i in 0 144 184
do
  mv dir-192.168.30.$i dir-10.0.30.$i
done


Phil


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-01 Thread James A. Peltier

adrian kok wrote:
Hi all 


how can I have script to rename the following
directory pattern from

 

from 

dir-192.168.30.0   
dir-192.168.30.144 
dir-192.168.30.184



To:


dir-10.0.30.0   
dir-10.0.30.144 
dir-10.0.30.184


If this is to rename individual files from 192.168.30.0=>192.168.30.144 then

for ((  i = 0 ;  i <= 143;  i++  ))
do
  mv 192.168.30.$i 10.0.30.$i
done


thank you


You're welcome.


http://www.freeos.com/guides/lsst/

--
James A. Peltier
Technical Director, RHCE
SCIRF | GrUVi @ Simon Fraser University - Burnaby Campus
Phone   : 778-782-3610
Fax : 778-782-3045
Mobile  : 778-840-6434
E-Mail  : [EMAIL PROTECTED]
Website : http://gruvi.cs.sfu.ca | http://scirf.cs.sfu.ca
MSN : [EMAIL PROTECTED]
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-11-01 Thread Frank Cox
On Fri, 02 Nov 2007 02:22:30 +0800 (CST)
adrian kok <[EMAIL PROTECTED]> wrote:

> how can I have script to rename the following
> directory pattern from
> 
> dir-192.168.30.0To: dir-10.0.30.0   

rename 192.168 10.0 dir*

-- 
MELVILLE THEATRE ~ Melville Sask ~ http://www.melvilletheatre.com
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] script help

2007-11-01 Thread adrian kok
Hi all 

how can I have script to rename the following
directory pattern from

 

from 

dir-192.168.30.0   
dir-192.168.30.144 
dir-192.168.30.184


To:


dir-10.0.30.0   
dir-10.0.30.144 
dir-10.0.30.184

thank you

Send instant messages to your online friends http://uk.messenger.yahoo.com 
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Stephen Harris
On Fri, Oct 26, 2007 at 06:56:05PM +0800, Anup Shukla wrote:

> MOUNTER=`ssh $i "mount | grep data | awk '{print \\$1,\\$2,\\$3}'"`
> 
> This is what i tried and worked for me.

Why not be simpler, run the "mount" on the remote machine but the grep
and awk on the local machine; no quoting issue at all then

  MOUNTER=`ssh $i mount | grep data | awk '{print $1,$2,$3}'`

(more network data, less remote processing)

-- 

rgds
Stephen
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Tom Brown




Correction.
MOUNTER=`ssh $i "mount | grep data | awk '{print \\$1,\\$2,\\$3}'"`

This is what i tried and worked for me.



bingo! gold star - thanks!!

I need to query mount as these are nfs mounts configre by an automounter 
and so not in the fstab


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Luciano Rocha
On Fri, Oct 26, 2007 at 11:52:50AM +0100, Luciano Rocha wrote:
> On Fri, Oct 26, 2007 at 11:28:37AM +0100, Tom Brown wrote:
> >  Hi
> > 
> >  I am sure the answer here is really easy but i am stuck!
> > 
> >  # mount | grep data | awk '{print$1,$2,$3}'
> > 
> >  gives me the info i require locally, however i need to execute this over 
> >  about 1000 hosts so i run things remotely using ssh something like
> > 
> >  # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
> > 
> >  however this fails as at the end of the line there are 2 ticks eg ' 
> > together 
> >  -
> > 
> >  Can anyone offer me some syntax help please?
> 
> Well, you don't need to run the grep and awk on the other side:
> 
> MOUNTER=`ssh $i mount | awk '/data/{print $1,$2,$3}'`
> 
> But you can live without the call to mount, too:
> MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab`

Oops, wrong c&p:
MOUNTER=`ssh $i awk "'/data/{print \$1,\$2,\$3}'" /etc/mtab`

-- 
lfr
0/0


pgpgNKGE83LSZ.pgp
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Luciano Rocha
On Fri, Oct 26, 2007 at 11:28:37AM +0100, Tom Brown wrote:
>  Hi
> 
>  I am sure the answer here is really easy but i am stuck!
> 
>  # mount | grep data | awk '{print$1,$2,$3}'
> 
>  gives me the info i require locally, however i need to execute this over 
>  about 1000 hosts so i run things remotely using ssh something like
> 
>  # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`
> 
>  however this fails as at the end of the line there are 2 ticks eg ' together 
>  -
> 
>  Can anyone offer me some syntax help please?

Well, you don't need to run the grep and awk on the other side:

MOUNTER=`ssh $i mount | awk '/data/{print $1,$2,$3}'`

But you can live without the call to mount, too:
MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab`

-- 
lfr
0/0


pgp1uB002Doex.pgp
Description: PGP signature
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Anup Shukla

Anup Shukla wrote:

Tom Brown wrote:




How about
# MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`


alas no

MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1, \$2, \$3}"'`

results in

awk: {print , , }
awk:^ syntax error
awk: {print , , }
awk:  ^ syntax error
awk: {print , , }
awk:^ syntax error
awk: cmd. line:1: {print , , }
awk: cmd. line:1: ^ unexpected newline or end of string



Sorry,

MOUNTER=`ssh $i 'mount | grep data | awk "{print \\$1,\\$2,\\$3}"'`



Correction.
MOUNTER=`ssh $i "mount | grep data | awk '{print \\$1,\\$2,\\$3}'"`

This is what i tried and worked for me.

Regards,
A.S
___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Anup Shukla

Tom Brown wrote:




How about
# MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`


alas no

MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1, \$2, \$3}"'`

results in

awk: {print , , }
awk:^ syntax error
awk: {print , , }
awk:  ^ syntax error
awk: {print , , }
awk:^ syntax error
awk: cmd. line:1: {print , , }
awk: cmd. line:1: ^ unexpected newline or end of string



Sorry,

MOUNTER=`ssh $i 'mount | grep data | awk "{print \\$1,\\$2,\\$3}"'`

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Tom Brown






How about
# MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`


alas no

MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1, \$2, \$3}"'`

results in

awk: {print , , }
awk:^ syntax error
awk: {print , , }
awk:  ^ syntax error
awk: {print , , }
awk:^ syntax error
awk: cmd. line:1: {print , , }
awk: cmd. line:1: ^ unexpected newline or end of string




oops and actually doing what you asked results in the same

MOUNTER=`ssh $i "mount | grep data | awk '{print \$1, \$2, \$3}'"`

awk: {print , , }
awk:^ syntax error
awk: {print , , }
awk:  ^ syntax error
awk: {print , , }
awk:^ syntax error
awk: cmd. line:1: {print , , }
awk: cmd. line:1: ^ unexpected newline or end of string

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Tom Brown




How about
# MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`


alas no

MOUNTER=`ssh $i 'mount | grep data | awk "{print \$1, \$2, \$3}"'`

results in

awk: {print , , }
awk:^ syntax error
awk: {print , , }
awk:  ^ syntax error
awk: {print , , }
awk:^ syntax error
awk: cmd. line:1: {print , , }
awk: cmd. line:1: ^ unexpected newline or end of string


___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Anup Shukla

Tom Brown wrote:


# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`



How about
# MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"`

Regards
A.S

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


Re: [CentOS] script help

2007-10-26 Thread Alfred von Campe

On Oct 26, 2007, at 6:28, Tom Brown wrote:


I am sure the answer here is really easy but i am stuck!


Getting the quoting right for remote commands in the shell is never  
an easy thing :-).



# mount | grep data | awk '{print$1,$2,$3}'

gives me the info i require locally, however i need to execute this  
over about 1000 hosts so i run things remotely using ssh something  
like


# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`

however this fails as at the end of the line there are 2 ticks eg '  
together -


Can anyone offer me some syntax help please?


I can usually get this to work with some trial an error by doubling  
up quotes and using backslahes but it's a frustrating experience.
Instead, I use a different technique: I put a script in a network  
accessible place (i.e., a common NFS mount) and then use ssh to  
execute that script.


Alfred

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


[CentOS] script help

2007-10-26 Thread Tom Brown

Hi

I am sure the answer here is really easy but i am stuck!

# mount | grep data | awk '{print$1,$2,$3}'

gives me the info i require locally, however i need to execute this over 
about 1000 hosts so i run things remotely using ssh something like


# MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''`

however this fails as at the end of the line there are 2 ticks eg ' 
together -


Can anyone offer me some syntax help please?

thanks

___
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos