Youssef Hammouma
Youssef Hammouma

Reputation: 151

awk condition for first line replacement

I have a shell that replace the first line of this file :

TABLE;APGFBEBA; ;
NoSS;CHAR(13);N° assuré;
DtDebExo;CHAR(8);Date début;

By this one :

01 APGFBEBA.

But i also have files that originally looks like this :

Table;APGFNOJF; ; ;

So i tried to add an "OR" condition to my awk command so i can replace those lines the same way i did it for the one above, but unfortunately it do not work

Here is my awk command :

awk -F ';' '
$1=="TABLE" && $3==" " || $1=="TABLE" && $4==" " {
  printf "01 %s.\n\n", $2;
  next
}

The first condition works, but not the second one

Upvotes: 1

Views: 218

Answers (1)

anubhava
anubhava

Reputation: 784898

Converting my comment to answer so that solution is easy to find for future visitors.

You don't need || conditions to match both lines as

awk -F ';' '
toupper($1)=="TABLE"  && $3 == " " {
   printf "01 %s.\n\n", $2
}' file

should work for both the lines.

Upvotes: 2

Related Questions