For Programmers: Free Programming Magazines  


Home > Archive > AWK > November 2004 > conditional replacement









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author conditional replacement
christian

2004-11-23, 3:55 pm

hi,

i would like replace line 2 if in line 4 for thousand of files?
Unlucky my below attempt works not until now, because i find no example in the web
how i refer to line 2 and 4 optimal and i'm not sure whta's the perfect tool -
bash only, sed or awk?

for i in * do ; awk `/type,1/ {sub(/lfdn,/,"lfdn,100")}` $i ; done

many
thanks
Christian
christian

2004-11-24, 3:55 pm

w_a_x_man@yahoo.com (William James) wrote in message news:<f8860640.0411212323.15e4edbe@posting.google.com>...
> ozric@web.de (christian) wrote
>
>
> -----
>
> # If "type,1" is found in line 4, then in line 2 "lfdn," needs to be
> # changed to "lfdn,100".
> NR > 1 && NR<5 {
> if ( 4==NR )
> { if ( $0 ~ /type,1/ )
> sub( /lfdn,/, "lfdn,100", a[2] )
> print a[2] "\n" a[3]
> print
> }
> else
> a[NR] = $0
> next
> }
>
> { print }
>
> -----
>
> Is this what you want?


Yes that's a perfect starting point - many thanks!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com