🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: es.comp.os.linux.programacion
5 messages
5 total messages Started by speeter Tue, 07 Mar 2006 15:21
Capturar ultimo caracter de una linea
#1258
Author: speeter
Date: Tue, 07 Mar 2006 15:21
8 lines
1152 bytes
Hola a todos

Estoy haciendo un script en bash y necesito capturar el ultimo caracter 
de una linea, en una variable.

Alguna idea?

Saludos
Re: Capturar ultimo caracter de una linea
#1259
Author: Pascal Bourguignon
Date: Tue, 07 Mar 2006 15:41
11 lines
1579 bytes
speeter <speeter@terra.es> writes:
> Estoy haciendo un script en bash y necesito capturar el ultimo
> caracter de una linea, en una variable.

linea="abcdef"
ultimo_caracter="${linea:$((${#linea}-1))}"
printf "%s\n" "$ultimo_caracter"


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Re: Capturar ultimo caracter de una linea
#1260
Author: speeter
Date: Tue, 07 Mar 2006 16:00
19 lines
1571 bytes
Pascal Bourguignon wrote:

> speeter <speeter@terra.es> writes:
> 
>>Estoy haciendo un script en bash y necesito capturar el ultimo
>>caracter de una linea, en una variable.
> 
> 
> linea="abcdef"
> ultimo_caracter="${linea:$((${#linea}-1))}"
> printf "%s\n" "$ultimo_caracter"
> 
> 
Gracias Pascal, funciona ok.

Donde (pagina man, manual, etc) puedo consultar la sintaxis de lo que me 
pones?

Saludos
Re: Capturar ultimo caracter de una linea
#1163
Author: Han Solo
Date: Tue, 07 Mar 2006 16:01
35 lines
1941 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

speeter <speeter@terra.es> writes:

> Hola a todos
>
> Estoy haciendo un script en bash y necesito capturar el ultimo
> caracter de una linea, en una variable.
>
> Alguna idea?

Seguro que se puede hacer mejor. A mīŋŊ me gusta el perl...

echo "Esto es una cadena de prueba"|perl -e 'while (<>){/(.)$/;print "$1\n"}'

Un Saludo
- -- 
Han Solo
The Rebel Alliance

Emacs is not on every system

So what? [...] Do you tell your administrative people to stick with
notepad.exe? Do you tell your fat kids they can only have the crummy
games that come with their video games or plain dress that comes with
Barbie?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>

iD8DBQFEDa384FjpJaPEp20RAjltAKCYynsa2dLanUWiRQ4I8PG8iT3sQQCeMMuw
x/FRH6Rs3cEOTdvMuhWnHP8=
=fc8Z
-----END PGP SIGNATURE-----
Re: Capturar ultimo caracter de una linea
#1164
Author: Pascal Bourguignon
Date: Tue, 07 Mar 2006 16:29
37 lines
2495 bytes
speeter <speeter@terra.es> writes:

> Pascal Bourguignon wrote:
>
>> speeter <speeter@terra.es> writes:
>> 
>>>Estoy haciendo un script en bash y necesito capturar el ultimo
>>>caracter de una linea, en una variable.
>> linea="abcdef"
>> ultimo_caracter="${linea:$((${#linea}-1))}"
>> printf "%s\n" "$ultimo_caracter"
>> 
> Gracias Pascal, funciona ok.
>
> Donde (pagina man, manual, etc) puedo consultar la sintaxis de lo que
> me pones?

Por supuesto, esta en:
   man bash


    [...]
       ${parameter:offset:length}
              Substring Expansion.  Expands  to  up  to  length  characters  of
              parameter  starting  at  the  character  specified by offset.  If
              length is omitted, expands to the substring of parameter starting
              at  the  character  specified  by  offset.  length and offset are
    [...]


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads