简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM