shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Usando awk + sub


From: Leslie Watter
Subject: Re: [shell-script] Usando awk + sub
Date: Mon, 1 Apr 2013 16:06:57 -0300

Oi Gustavo,

Vc já tentou usar o gsub do awk ?

      gsub(r, s [, t])        For each substring matching the regular
expression r in the
                               string t, substitute the string s, and
return the number of
                               substitutions.   If t is not supplied, use
$0.  An & in the
                               replacement text is replaced with the text
that  was  actu*
                               ally  matched.   Use  \& to get a literal &.
 (This must be
                               typed as "\\&"; see GAWK: Effective AWK
Programming  for  a
                               fuller  discussion  of the rules for &’s and
backslashes in
                               the replacement text of sub(), gsub(), and
gensub().)

$ cat /tmp/x ; cat /tmp/x | awk 'gsub(/-/," ",$0); gsub(/\./," ",$0)'
.a-b,c-a
.a b,c a
 a b,c a


repare que mostro o /tmp/x e depois vou aplicando as regexps


[]s


LEslie



2013/4/1 Gustavo Soares [SLot] <address@hidden>

> **
>
>
> Pessoal, gostaria de uma ajudinha com o awk, usando o sub, consegui
> usando a linha abaixo, mas não gostaria de usar o sed, mas fazer tudo
> direto no awk.
>
> root@testejava:/root>awk 'NR=1 {if ( $1 == "JasperPrint" ) print $2}'
> /tmp/jasper.txt
> LBANCO.703-687
> root@testejava:/root>awk 'NR=1 {if ( $1 == "JasperPrint" ) print $2}'
> /tmp/jasper.txt | sed 's|\.| |g;s|-| |g'
> LBANCO 703 687
> root@testejava:/root>
>
> O que gostaria era de trocar o "." e o "-" por espaço.
>
> --
> -------------------
> SLot
> Linux User: 124842
> XMPP: address@hidden
>
>  
>



-- 
Leslie H. Watter


[As partes desta mensagem que não continham texto foram removidas]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]