Re: [expert] bash scripting question - simple regular expression?

2003-01-15 Thread Todd Lyons
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim C wrote on Tue, Jan 14, 2003 at 07:28:07PM -0800 :

> >newldif="./file2"
> Herein lies part of the problem.
> I don't want to use a file for scaleability reasons and I can't think of 
> any reason why it should be nescesary.  In theory I should be able to 
> store all of the text in a shell variable and then redirect the output 
> of echo to ldapadd.  So far I can get the text in but when I pass it to 

You're right, this is part of the problem.  Shell variables don't keep
the newline characters.  Witness:

[todd@fiji ~/tmp]$ cat file1 
#!/bin/bash

TEMP="line1
line2
line3"

echo $TEMP
[todd@fiji ~/tmp]$ ./file1 
line1 line2 line3

I don't see why you just don't do this:

#!/bin/bash

if [ ! $1 ]; then
echo "Sorry, you must pass the userid to add to directory."
exit 1
fi

binddn="cn=root,dc=microverse,dc=net"
pw4binddn="[deleted for security]"
ldaphost="ldap://localhost";
base="ou=Computers,dc=microverse,dc=net"
basetest="ou=People,dc=microverse,dc=net"
minimumUID=501
groupnum=421

# 1. Search the LDAP database and return all uidNumber attributes in a 
# given base

store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x "(cn=*)" uidNumber | \
 grep uidNumber | \
 sed -e 's/^uidNumber://' | sort -nr | head -n 1`

newtest=`ldapsearch -LLL -D $binddn -H $ldaphost -b$basetest -x "(cn=*)" uidNumber | \
 grep uidNumber | \
 sed -e 's/^uidNumber://' | sort -nr`
echo ${newtest[0]}

#It is best not to start at 0 or 1 as these could be privledged.

if [ "$store" = "" ]
then
store=$minimumUID
else
store=`expr $store + 1`
fi

LDAPADD="ldapadd -vx -D $binddn -W $pw4binddn"

$LDAPADD 

Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Jim C
Herein lies part of the problem.
I don't want to use a file for scaleability reasons and I can't think of 
any reason why it should be nescesary.  In theory I should be able to 
store all of the text in a shell variable and then redirect the output 
of echo to ldapadd.  So far I can get the text in but when I pass it to 
ldapadd it executes, returns no error messages but the new record does 
not show up on the ldap server.  Since it works from the command line 
using an ldif file it logically cannot be an issue of access to the 
server.  Also, no encryption is currently enabled.  Now

Whoops, accidentally sent the message before finishing it.
As I was going to say, the idea of not having the delimiters correct has 
some merit as I wouldn't know either way.  How can I check or set them?



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Jim C
echo $newldif

This produces:

[root@enigma scripts]# ./adduser adlfalj
./adduser: line 42: $newldif: ambiguous redirect

You've got something else going on cause it works on mine.  (Are you
sure that you're using the bash shell?)


[root@enigma scripts]# echo $SHELL
/bin/bash
[root@enigma scripts]#


[todd@fiji ~/tmp]$ cat file1
#!/bin/bash
#
newldif="./file2"


Herein lies part of the problem.
I don't want to use a file for scaleability reasons and I can't think of 
any reason why it should be nescesary.  In theory I should be able to 
store all of the text in a shell variable and then redirect the output 
of echo to ldapadd.  So far I can get the text in but when I pass it to 
ldapadd it executes, returns no error messages but the new record does 
not show up on the ldap server.  Since it works from the command line 
using an ldif file it logically cannot be an issue of access to the 
server.  Also, no encryption is currently enabled.  Now

#
cat > $newldif <
...

description: Machine Account


...


Post the WHOLE script so we can see what you're doing.  If you change
anything make sure you say exactly what you change.


It's a mess so remember, you asked for it. ;-)
I've been doing all kinds of tests to try and figure a way around the 
problem.  The algorithm works like this:

1. Get a list of uidNumbers
2. Sort them.
3. Take the one off the top (the largest)
4. Add one to it.
5. Create the text of a new record using the new uidNumber.


#!/bin/bash

binddn="cn=root,dc=microverse,dc=net"
pw4binddn="[deleted for security]"
ldaphost="ldap://localhost";
base="ou=Computers,dc=microverse,dc=net"
basetest="ou=People,dc=microverse,dc=net"
minimumUID=501
groupnum=421

#complete=`echo $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 
$line9 $line10 $line11 $line12`
#ldapsearch -LL -v -D "cn=proxyuser,dc=microverse,dc=net" -H 
ldap://localhost -b"dc=microverse,dc=net" -x "(cn=proxyuser)"

#1. Search the LDAP database and return all uidNumber attributes in a 
given base

store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x "(cn=*)" 
uidNumber | \
grep uidNumber | \
sed -e 's/^uidNumber: 
//' | sort -nr | head -n 1`

newtest=`ldapsearch -LLL -D $binddn -H $ldaphost -b$basetest -x "(cn=*)" 
uidNumber | \
grep uidNumber | \
sed -e 's/^uidNumber: 
//' | sort -nr`
echo ${newtest[0]}

#It is best not to start at 0 or 1 as these could be privledged.

if [ "$store" = "" ]
then
store=$minimumUID
else
store=`expr $store + 1`
fi

#ldapadd -x -D $binddn -w $pw4binddn
line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net\n";
line2="objectClass: top\n"
line3="objectClass: account\n"
line4="objectClass: posixAccount\n"
line5="uidNumber: $store\n"
line6="uid: $1\n"
line7="cn: $1\n"
line8="gidNumber: $groupnum\n"
line9="homeDirectory: /dev/null\n"
line10="loginShell: /bin/false\n"
line11="gecos: Machine Account\n"
line12="description: Machine Account\n"

output=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12

echo -e "$output" | ldapadd -vx -D $binddn -W $pw4binddn

echo -e "$output" > ldapadd -vx -D $binddn -W $pw4binddn

echo -e $output

echo -e $output > test.ldif

#cat $output
#echo $output

#$output <
#dn: uid=$1,ou=Computers,dc=microverse,dc=net
#objectClass: top
#objectClass: account
#objectClass: posixAccount
#uidNumber: $store
#uid: $1
#cn: $1
#gidNumber: $groupnum
#homeDirectory: /dev/null
#loginShell: /bin/false
#gecos: Machine Account
#description: Machine Account
#hrdoc


#cat $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9 
$line10 $line11 $line12 > ldapadd -x -D $binddn -w $pw4binddn

#complt=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12

#echo `expr $store + 1`




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Jim C
jipe wrote:

here is what says man:
The  entry  information  is read  from  standard input or from file through the use of the -f option.

so why not to try this:
echo -e "$output" | ldapadd -x -D "cn=root,dc=microverse,dc=net"


This produces an error, i.e. I get the usage text for ldapadd if I try it.





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Todd Lyons
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim C wrote on Tue, Jan 14, 2003 at 11:31:20AM -0800 :
> I finally got around to giving your suggestion a try. :-)
> 
> cat > $newldif < dn: uid=$1,ou=Computers,dc=microverse,dc=net
> objectClass: top
> objectClass: account
> objectClass: posixAccount
> uidNumber: $store
> uid: $1
> cn: $1
> gidNumber: $groupnum
> homeDirectory: /dev/null
> loginShell: /bin/false
> gecos: Machine Account
> description: Machine Account
> hrdoc
> 
> echo $newldif
> 
> This produces:
> 
> [root@enigma scripts]# ./adduser adlfalj
> ./adduser: line 42: $newldif: ambiguous redirect

You've got something else going on cause it works on mine.  (Are you
sure that you're using the bash shell?)

[todd@fiji ~/tmp]$ cat file1
#!/bin/bash
#
newldif="./file2"
#
cat > $newldif < This causes the script to halt at some point and gives no output if you 
> replace the 'cat' with 'echo'.

Sounds like
1) You've got a misplaced backtick.
2) You're using different delimiters for the << hrdoc start point and
hrdoc endpoint.

Post the WHOLE script so we can see what you're doing.  If you change
anything make sure you say exactly what you change.

> >All you gotta do is change the "command" portion of the above that I
> >quoted:
> >
> >#!/bin/bash
> >ldapadd -x blah blah blah  < >dn: uid=$1,ou=Computers,dc=microverse,dc=net
> >objectClass: top
> >objectClass: account
> >objectClass: posixAccount
> >uidNumber: $store
> >uid: $1
> >cn: $1
> >gidNumber: $groupnum
> >homeDirectory: /dev/null
> >loginShell: /bin/false
> >gecos: Machine Account
> >description: Machine Account
> >hrdoc

What I said originally should still work.

Blue skies...   Todd
- -- 
   MandrakeSoft USA   http://www.mandrakesoft.com
  cat /boot/vmlinuz > /dev/dsp  #for great justice
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+JLl8lp7v05cW2woRAuSQAKDOd7bKbEgO3kt6eL8SLrZHLcwwHACcCSWk
r7X2YShaye9fOJwX7rcsyWQ=
=559n
-END PGP SIGNATURE-


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread jipe
On Tue, 14 Jan 2003 12:58:30 -0800
Jim C <[EMAIL PROTECTED]> wrote:

> Grrr!!
> 
> What gets me is why this doesn't work:
> 
> echo -e $output > ldapadd -x -D $binddn -W $pw4binddn
> 
> where echo -e produces:
> 
> [root@enigma scripts]# ./adduser alkjdfal 
> 
> dn: uid=alkjdfal,ou=Computers,dc=microverse,dc=net
> objectClass: top
> objectClass: account
> objectClass: posixAccount
> uidNumber: 501
> uid: alkjdfal
> cn: alkjdfal
> gidNumber: 421
> homeDirectory: /dev/null
> loginShell: /bin/false
> gecos: Machine Account
> description: Machine Account
> 
> 502 <--different echo statement
> 
> If I do echo -e $output > test.ldif
> and then
> ldapadd -x -D "cn=root,dc=microverse,dc=net" -f test.ldif from the 
> command line it works fine!  Do you think this is a bug in ldapadd?
> 
>

here is what says man:
The  entry  information  is read  from  standard input or from file through the use of 
the -f option.

so why not to try this:
echo -e "$output" | ldapadd -x -D "cn=root,dc=microverse,dc=net"

bye
jipe


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Jim C
Grrr!!

What gets me is why this doesn't work:

echo -e $output > ldapadd -x -D $binddn -W $pw4binddn

where echo -e produces:

[root@enigma scripts]# ./adduser alkjdfal 

dn: uid=alkjdfal,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: 501
uid: alkjdfal
cn: alkjdfal
gidNumber: 421
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account

502 <--different echo statement

If I do echo -e $output > test.ldif
and then
ldapadd -x -D "cn=root,dc=microverse,dc=net" -f test.ldif from the 
command line it works fine!  Do you think this is a bug in ldapadd?

Todd Lyons wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 :


What I am trying to do is create a sort of virtual file.
I've already tried using the here document and it doesn't seem to be 
working for me.  What I am trying to do exactly is create an LDIF file 
for passing to an LDAP database.  I have each line stored in an 
individual shell variable like so:


There are two ways to do this:
1) Create an ldif file, then call ldap* with that ldif file.
2) Just pass it all to ldap* on stdin.



The syntax I've been trying looks like this:
ldapadd -x -D $binddn -w "placepasswordhere" <



Look at this:

#!/bin/bash
cat > $1.ldif  <
In all cases the here document doesn't seem to make it to the ldapadd 
command which I know reads from standard-in.


All you gotta do is change the "command" portion of the above that I
quoted:

#!/bin/bash
ldapadd -x blah blah blah  <
dn: uid=$1,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: $store
uid: $1
cn: $1
gidNumber: $groupnum
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account
hrdoc

Blue skies...			Todd
- -- 
   MandrakeSoft USA   http://www.mandrakesoft.com
Mandrake: An amalgam of good ideas from RedHat, Debian, and MandrakeSoft.
All in all, IMHO, an unbeatable combination.   --Levi Ramsey on Cooker ML
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+Iy/Ylp7v05cW2woRAhwMAJoDELaI+O82WNuz5SRnujaXG5y7hQCfUdlY
dCj3ZneaqniZkaaADmAFVD4=
=O07o
-END PGP SIGNATURE-





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-14 Thread Jim C
I finally got around to giving your suggestion a try. :-)

cat > $newldif <
dn: uid=$1,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: $store
uid: $1
cn: $1
gidNumber: $groupnum
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account
hrdoc

echo $newldif

This produces:

[root@enigma scripts]# ./adduser adlfalj
./adduser: line 42: $newldif: ambiguous redirect


$newldif <
dn: uid=$1,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: $store
uid: $1
cn: $1
gidNumber: $groupnum
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account
hrdoc

cat $newldif

This causes the script to halt at some point and gives no output if you 
replace the 'cat' with 'echo'.





Todd Lyons wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 :


What I am trying to do is create a sort of virtual file.
I've already tried using the here document and it doesn't seem to be 
working for me.  What I am trying to do exactly is create an LDIF file 
for passing to an LDAP database.  I have each line stored in an 
individual shell variable like so:


There are two ways to do this:
1) Create an ldif file, then call ldap* with that ldif file.
2) Just pass it all to ldap* on stdin.



The syntax I've been trying looks like this:
ldapadd -x -D $binddn -w "placepasswordhere" <



Look at this:

#!/bin/bash
cat > $1.ldif  <
In all cases the here document doesn't seem to make it to the ldapadd 
command which I know reads from standard-in.


All you gotta do is change the "command" portion of the above that I
quoted:

#!/bin/bash
ldapadd -x blah blah blah  <
dn: uid=$1,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: $store
uid: $1
cn: $1
gidNumber: $groupnum
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account
hrdoc

Blue skies...			Todd
- -- 
   MandrakeSoft USA   http://www.mandrakesoft.com
Mandrake: An amalgam of good ideas from RedHat, Debian, and MandrakeSoft.
All in all, IMHO, an unbeatable combination.   --Levi Ramsey on Cooker ML
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+Iy/Ylp7v05cW2woRAhwMAJoDELaI+O82WNuz5SRnujaXG5y7hQCfUdlY
dCj3ZneaqniZkaaADmAFVD4=
=O07o
-END PGP SIGNATURE-





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-13 Thread Todd Lyons
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jim C wrote on Mon, Jan 13, 2003 at 10:16:41AM -0800 :
> 
> What I am trying to do is create a sort of virtual file.
> I've already tried using the here document and it doesn't seem to be 
> working for me.  What I am trying to do exactly is create an LDIF file 
> for passing to an LDAP database.  I have each line stored in an 
> individual shell variable like so:

There are two ways to do this:
1) Create an ldif file, then call ldap* with that ldif file.
2) Just pass it all to ldap* on stdin.

> The syntax I've been trying looks like this:
> ldapadd -x -D $binddn -w "placepasswordhere" < line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net";
> line2="objectClass: top"


Look at this:

#!/bin/bash
cat > $1.ldif  < In all cases the here document doesn't seem to make it to the ldapadd 
> command which I know reads from standard-in.

All you gotta do is change the "command" portion of the above that I
quoted:

#!/bin/bash
ldapadd -x blah blah blah  

Re: [expert] bash scripting question - simple regular expression?

2003-01-13 Thread Jim C
Great but now I have another problem.

What I am trying to do is create a sort of virtual file.
I've already tried using the here document and it doesn't seem to be 
working for me.  What I am trying to do exactly is create an LDIF file 
for passing to an LDAP database.  I have each line stored in an 
individual shell variable like so:

line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net";
line2="objectClass: top"
line3="objectClass: account"
line4="objectClass: posixAccount"
line5="uidNumber: $store"
line6="uid: $1"
line7="cn: $1"
line8="gidNumber: $groupnum"
line9="homeDirectory: /dev/null"
line10="loginShell: /bin/false"
line11="gecos: Machine Account"
line12="description: Machine Account"

The syntax I've been trying looks like this:

ldapadd -x -D $binddn -w "placepasswordhere" <
line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net";
line2="objectClass: top"
line3="objectClass: account"
line4="objectClass: posixAccount"
line5="uidNumber: $store"
line6="uid: $1"
line7="cn: $1"
line8="gidNumber: $groupnum"
line9="homeDirectory: /dev/null"
line10="loginShell: /bin/false"
line11="gecos: Machine Account"
line12="description: Machine Account"
hrdoc

I've also tried it with newlines at the end of each line like so:

ldapadd -x -D $binddn -w "placepasswordhere" <
line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net\n";
line2="objectClass: top\n"
line3="objectClass: account\n"
line4="objectClass: posixAccount\n"
line5="uidNumber: $store\n"
line6="uid: $1\n"
line7="cn: $1\n"
line8="gidNumber: $groupnum\n"
line9="homeDirectory: /dev/null\n"
line10="loginShell: /bin/false\n"
line11="gecos: Machine Account\n"
line12="description: Machine Account\n"
hrdoc

In all cases the here document doesn't seem to make it to the ldapadd 
command which I know reads from standard-in.  I've also tried the -f 
switch which is for specifiying a filename.

Anybody got a clue here?

jipe wrote:
On Sun, 12 Jan 2003 09:15:50 -0800
Mark Alexander <[EMAIL PROTECTED]> wrote:



On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote:


I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.


#!/bin/sh
LIST="42 666 1776 2001"
echo $LIST | sed -e 's/^\([0-9]*\).*/\1/'





LIST="42 666 1776 2001"
echo ${LIST%% *} --> 42
or
LIST=(42 666 1776 2001)
echo ${LIST[0]} --> 42

both are about 5 times faster than a pipe with sed.

bye
jipe





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-13 Thread Jim C
Wow.  I didn't know bash had arrays.  Kool. :-)

jipe wrote:

On Sat, 11 Jan 2003 17:56:16 -0800
Jim C <[EMAIL PROTECTED]> wrote:



I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.






bash you said, so use only bash.

array=($(your_command_to_create_the list_of_intergers))
echo ${array[0]}
this displays the 1rst integer from your list.

echo ${#array[*]} displays the number of integers
echo ${array[$((${#array[*]}-1))]} displays the last integer
etc...
maybe you'll have to set IFS. depends of the separator.

bye
jipe





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread jipe
On Sun, 12 Jan 2003 09:15:50 -0800
Mark Alexander <[EMAIL PROTECTED]> wrote:

> On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote:
> > I have a list of positive integers of which I only want the first one.
> > They are of arbitrary size. How can I cut the rest of them off?
> > I've been trying to write a regular expression for this using sed or awk.
> 
> #!/bin/sh
> LIST="42 666 1776 2001"
> echo $LIST | sed -e 's/^\([0-9]*\).*/\1/'
> 
> 

LIST="42 666 1776 2001"
echo ${LIST%% *} --> 42
or
LIST=(42 666 1776 2001)
echo ${LIST[0]} --> 42

both are about 5 times faster than a pipe with sed.

bye
jipe


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread jipe
On Sat, 11 Jan 2003 17:56:16 -0800
Jim C <[EMAIL PROTECTED]> wrote:

> I have a list of positive integers of which I only want the first one.
> They are of arbitrary size. How can I cut the rest of them off?
> I've been trying to write a regular expression for this using sed or awk.
> 
> 
> 

bash you said, so use only bash.

array=($(your_command_to_create_the list_of_intergers))
echo ${array[0]}
this displays the 1rst integer from your list.

echo ${#array[*]} displays the number of integers
echo ${array[$((${#array[*]}-1))]} displays the last integer
etc...
maybe you'll have to set IFS. depends of the separator.

bye
jipe


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread Mark Alexander
On Sat, Jan 11, 2003 at 05:56:16PM -0800, Jim C wrote:
> I have a list of positive integers of which I only want the first one.
> They are of arbitrary size. How can I cut the rest of them off?
> I've been trying to write a regular expression for this using sed or awk.

#!/bin/sh
LIST="42 666 1776 2001"
echo $LIST | sed -e 's/^\([0-9]*\).*/\1/'


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread Toshiro
> >>>I have a list of positive integers of which I only want the first one.
> >>>They are of arbitrary size. How can I cut the rest of them off?
> >>>I've been trying to write a regular expression for this using sed or
> >>> awk.
> >
> > you don't specify the format of  the integers.  are they space separated
> > and all on one line?  or are they line separated (each integer on
> > its own line)?
> >
> > are there blank spaces (if the first) or blank lines (if the second)
> > before the first integer?
>
> Blank spaces are between the numbers.
>

In awk is pretty simple, just do:
awk '{ print $1 }'  filename

(where filename is the name of the file with the numbers)

 I'm assuming you have only one line in that file, if you have more than one 
line and you want to specify which line to print do:
awk '{ if ( NR==line_number ) print $1 } filename

-- 
Toshiro


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread Jim C
On Saturday 11 January 2003 08:56 pm, Jim C wrote:


I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.




you don't specify the format of  the integers.  are they space separated
and all on one line?  or are they line separated (each integer on
its own line)?

are there blank spaces (if the first) or blank lines (if the second) before
the first integer?


Blank spaces are between the numbers.


or are they in some other format?  you say they're arbitrary size, so does
that mean they aren't in some fixed column format?\


No fixed columns.  What they are is a line of userids with spaces 
between them.

if they're one integer to a line, then head (for the first), tail (for the 
last), or some combination of head and tail (for anything in between)
will get you the integer you want.

There is only one line... but that is a good idea.  I might be able to 
arrange for them to be in one column.  Then I could use head. :-)  I'll 
try that and let you know.

if they're delimited by something (spaces, commas, colons, whatever),
then cut -f  -d ""  might help.  otherwise,
well, sed, awk, or some custom program in your favorite language.


sed and awk are driving me nuts. ;-)


if there are blank lines or blank fields before the first number, then
some sort of bash while loop would be needed to ignore the
blank lines or blank fields, print the first non-blank field, and then
exit the loop.





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-12 Thread Jim C
The are already sorted.  I just need the largest one which is the first one.

Mark Weaver wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Saturday 11 January 2003 08:56 pm, Jim C wrote:


I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.



without sorting them or anything why not just use a while loop with a counter?

Mark
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+IM23JuZ1geTzHgERAmKPAKDSouh+GrtkZTPj9o5CDvTG7tIEtgCgjOZk
buhxrkvmzeqXdrW7n0a8ACk=
=Mw7P
-END PGP SIGNATURE-






Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com





Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-11 Thread Bopolissimus Platypus
> On Saturday 11 January 2003 08:56 pm, Jim C wrote:
> > I have a list of positive integers of which I only want the first one.
> > They are of arbitrary size. How can I cut the rest of them off?
> > I've been trying to write a regular expression for this using sed or awk.

you don't specify the format of  the integers.  are they space separated
and all on one line?  or are they line separated (each integer on
its own line)?

are there blank spaces (if the first) or blank lines (if the second) before
the first integer?

or are they in some other format?  you say they're arbitrary size, so does
that mean they aren't in some fixed column format?

if they're one integer to a line, then head (for the first), tail (for the 
last), or some combination of head and tail (for anything in between)
will get you the integer you want.

if they're delimited by something (spaces, commas, colons, whatever),
then cut -f  -d ""  might help.  otherwise,
well, sed, awk, or some custom program in your favorite language.

if there are blank lines or blank fields before the first number, then
some sort of bash while loop would be needed to ignore the
blank lines or blank fields, print the first non-blank field, and then
exit the loop.

tiger

-- 
Gerald Timothy Quimpo  tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"
   Veritas liberabit vos.
   Doveryai no proveryai.


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] bash scripting question - simple regular expression?

2003-01-11 Thread Mark Weaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Saturday 11 January 2003 08:56 pm, Jim C wrote:
> I have a list of positive integers of which I only want the first one.
> They are of arbitrary size. How can I cut the rest of them off?
> I've been trying to write a regular expression for this using sed or awk.

without sorting them or anything why not just use a while loop with a counter?

Mark
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+IM23JuZ1geTzHgERAmKPAKDSouh+GrtkZTPj9o5CDvTG7tIEtgCgjOZk
buhxrkvmzeqXdrW7n0a8ACk=
=Mw7P
-END PGP SIGNATURE-



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



[expert] bash scripting question - simple regular expression?

2003-01-11 Thread Jim C
I have a list of positive integers of which I only want the first one.
They are of arbitrary size. How can I cut the rest of them off?
I've been trying to write a regular expression for this using sed or awk.




Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Bash Scripting

2000-06-10 Thread Brian T. Schellenberger

Necrotica wrote:
> 
> I'm interested in learning a little about bash scripting. In particular, I'd
> like to learn how to tell if the user logging on is logging in under X or from
> a command prompt. Can anyone point me in the direction of where I can find this
> information? Thanks...
> 
> -Chris

Just see if $DISPLAY is set.  (Sorry: I only know csh; there it's
$?DISPLAY, but probably not the same for bash.)

-- 
"Brian, the man from babble-on"  [EMAIL PROTECTED]
Brian T. Schellenberger  http://www.babbleon.org
Support http://www.eff.org.  Support decss defendents.
Support http://www.programming-freedom.org.  Boycott amazon.com.




Re: [expert] Bash Scripting

2000-06-10 Thread Necrotica

Thanks for the help, guys. That was exactly what I was looking for!

-Chris


On Sat, 10 Jun 2000, Civileme wrote:
> Civileme wrote:
> > 
> > Necrotica wrote:
> > >
> > > I'm interested in learning a little about bash scripting. In particular, I'd
> > > like to learn how to tell if the user logging on is logging in under X or from
> > > a command prompt. Can anyone point me in the direction of where I can find this
> > > information? Thanks...
> > >
> > > -Chris
> > 
> > printenv from Konsole when you are logged in in graphics mode
> > 
> > printenv from a console (logged in on runlevel 3)
> > 
> > Check the settings of the DISPLAY variable
> > 
> > Civileme
> 
> Ummm...  Well under the console perhaps better to printenv |
> less  (blush).  That fills more than a screen!
> 
> 
> The point is DISPLAY has a value in graphics mode and does NOT
> exist in console
> 
> So 
> 
> if [ $DISPLAY ] then
>   # DISPLAY is set and is a nonzero length string so do GUI stuff
> elif [ -z $DISPLAY ]
> #  do the console stuf here  (length of string is zero)
> else
>   #  do any other stuff here
> fi
> 
> Civileme




Re: [expert] Bash Scripting

2000-06-10 Thread Civileme

Civileme wrote:
> 
> Necrotica wrote:
> >
> > I'm interested in learning a little about bash scripting. In particular, I'd
> > like to learn how to tell if the user logging on is logging in under X or from
> > a command prompt. Can anyone point me in the direction of where I can find this
> > information? Thanks...
> >
> > -Chris
> 
> printenv from Konsole when you are logged in in graphics mode
> 
> printenv from a console (logged in on runlevel 3)
> 
> Check the settings of the DISPLAY variable
> 
> Civileme

Ummm...  Well under the console perhaps better to printenv |
less  (blush).  That fills more than a screen!


The point is DISPLAY has a value in graphics mode and does NOT
exist in console

So 

if [ $DISPLAY ] then
# DISPLAY is set and is a nonzero length string so do GUI stuff
elif [ -z $DISPLAY ]
#  do the console stuf here  (length of string is zero)
else
#  do any other stuff here
fi

Civileme




Re: [expert] Bash Scripting

2000-06-10 Thread Civileme

Necrotica wrote:
> 
> I'm interested in learning a little about bash scripting. In particular, I'd
> like to learn how to tell if the user logging on is logging in under X or from
> a command prompt. Can anyone point me in the direction of where I can find this
> information? Thanks...
> 
> -Chris

printenv from Konsole when you are logged in in graphics mode

printenv from a console (logged in on runlevel 3)

Check the settings of the DISPLAY variable

Civileme




[expert] Bash Scripting

2000-06-10 Thread Necrotica

I'm interested in learning a little about bash scripting. In particular, I'd
like to learn how to tell if the user logging on is logging in under X or from
a command prompt. Can anyone point me in the direction of where I can find this
information? Thanks...

-Chris