[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] bash script, substitution



Kristian Nørgaard wrote:
> Hvordan erstatter jeg den ottende (8.) forekomst
> af \t i hver linie med \tXXX ?

[^\t]+ er en sekvens af ikke tabulator tegn.

Så hvad et regulært udtryk af formen:

s/^([^\t]+\t[^\t]+\t[^\t]+\t)(.*)$/"$1XXX$2"/ge;

Den ville lave "A\tB\tC\tD\t.." om til
"A\tB\tC\tXXXD\t.."

/e betyder at "$1XXX$2" tolkes som perlcode og ikke
strengen der skal substituteres ind, og $1 og $2 referere
til hvad der matches af de to par af parenteser i det regulære
udtryk.

Et simplere alternativ med split og join

for hver linie:
{
@test = split "\t",$linie;
$test[8]="XXX".$test[8];
print join "\t",@test;
}

-- 
  Mvh. Carsten Svaneborg
http://gauss.ffii.org


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-02-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *