FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 02-10-2012, 06:38 AM
sheraz naz
 
Default script regular expression

--- On Fri, 2/10/12, Alejandro Rodriguez Luna <el_alexluna@yahoo.com.mx> wrote:

> From: Alejandro Rodriguez Luna <el_alexluna@yahoo.com.mx>
> Subject: [CentOS] script regular expression
> To: "CentOS mailing list" <centos@centos.org>
> Date: Friday, February 10, 2012, 1:29 AM
> Hi everyone, I was creating a script
> and i found something i can't figure out.
>
> #/bin/bash
> for i in $(cat certificates.txt)
> do*
> *** echo $i
> done
>
> I expected this
>
> RSA Secure Server Certification Authority
> VeriSign Class 1 CA Individual Subscriber-Persona Not
> Validated
>
>
> but i got this
>
> RSA
> Secure
> Server
> Certification
> Authority
> VeriSign
> Class
> 1
> CA
> Individual
> Subscriber-Persona
> Not
> Validated
>
> *any ideas how to fix this? i mean, how can i get the whole
> line instead of word by word?

Try:
while read i;do echo $i;done < certificates.txt

Thanks
Sheraz
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-10-2012, 09:27 AM
Marc Deop
 
Default script regular expression

On Thursday 09 February 2012 23:38:51 sheraz naz wrote:
> > #/bin/bash
> > for i in $(cat certificates.txt)
> > do
> > echo $i
> > done
> >

Bad practice.
>
> Try:
> while read i;do echo $i;done < certificates.txt
> --

That's the right solution, but don't forget to always quote your variables "$i"

Regards

PS: you sometimes might need "read -r"

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-10-2012, 12:59 PM
Leonard den Ottolander
 
Default script regular expression

Hello Alejandro,

On Thu, 2012-02-09 at 23:29 -0800, Alejandro Rodriguez Luna wrote:
> #/bin/bash
> for i in $(cat certificates.txt)
> do
> echo $i
> done

(As people already pointed out in case the input is coming from a file
you should use a redirect.)

What you see has to do with the internal field separator (IFS), which is
usually set to space, tab and newline. Each of these characters is
considered a field separator i.e. a break point in your list. You can
read up on this at
http://www.tldp.org/LDP/abs/html/internalvariables.html#IFSH .

Regards,
Leonard.

--
mount -t life -o ro /dev/dna /genetic/research


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-10-2012, 01:47 PM
Steve Brooks
 
Default script regular expression

On Thu, 9 Feb 2012, Alejandro Rodriguez Luna wrote:


Hi everyone, I was creating a script and i found something i can't figure out.

#/bin/bash
for i in $(cat certificates.txt)
do*
*** echo $i
done

I expected this

RSA Secure Server Certification Authority
VeriSign Class 1 CA Individual Subscriber-Persona Not Validated


but i got this

RSA
Secure
Server
Certification
Authority
VeriSign
Class
1
CA
Individual
Subscriber-Persona
Not
Validated

*any ideas how to fix this? i mean, how can i get the whole line instead of word by word?


This will make it work your way.

--------------------------------------------------------------------
#!/bin/sh

IFS="
"
for i in `cat certificates.txt` ; do
echo $i
done
--------------------------------------------------------------------

Cheers,

Steve_____________________________________________ __
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-10-2012, 02:59 PM
 
Default script regular expression

Steve Brooks wrote:
> On Thu, 9 Feb 2012, Alejandro Rodriguez Luna wrote:
>
>> Hi everyone, I was creating a script and i found something i can't
>> figure out.
>>
>> #/bin/bash
>> for i in $(cat certificates.txt)
>> do*
>> *** echo $i
>> done
>>
>> I expected this
>>
>> RSA Secure Server Certification Authority
>> VeriSign Class 1 CA Individual Subscriber-Persona Not Validated
>>
>>
>> but i got this
>>
>> RSA
>> Secure
<snip>

Sure will. i is in the list RSA Secure etc. and each word is a member of
the list, separated by whitespace. Y'know, it would be a lot easier to do
awk '{print $0;}' certificates.txt, which would be exactly what you want.

mark


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 02-10-2012, 03:37 PM
Alejandro Rodriguez Luna
 
Default script regular expression

THanks all who gave me an answer, i found this doc and helped me. Thanks again

http://mywiki.wooledge.org/DontReadLinesWithFor

*
----------------------------------
Alejandro Rodriguez Luna
E-mail: el_alexluna@yahoo.com.mx
Movil: 044-311-112-86-41
----------------------------------


________________________________
De: "m.roth@5-cent.us" <m.roth@5-cent.us>
Para: CentOS mailing list <centos@centos.org>
Enviado: Viernes, 10 de febrero, 2012 9:59:35
Asunto: Re: [CentOS] script regular expression

Steve Brooks wrote:
> On Thu, 9 Feb 2012, Alejandro Rodriguez Luna wrote:
>
>> Hi everyone, I was creating a script and i found something i can't
>> figure out.
>>
>> #/bin/bash
>> for i in $(cat certificates.txt)
>> do*
>> *** echo $i
>> done
>>
>> I expected this
>>
>> RSA Secure Server Certification Authority
>> VeriSign Class 1 CA Individual Subscriber-Persona Not Validated
>>
>>
>> but i got this
>>
>> RSA
>> Secure
<snip>

Sure will. i is in the list RSA Secure etc. and each word is a member of
the list, separated by whitespace. Y'know, it would be a lot easier to do
awk '{print $0;}' certificates.txt, which would be exactly what you want.

* * * mark


_______________________________________________
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
 

Thread Tools




All times are GMT. The time now is 09:00 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org