-1

I use awk in the following command to return app names on my phone:

aapt dump badging App.apk | awk -F: '/label-uk/ {print $2}'

The problem is, I found that some of them use different labels like "label-en-GB" instead. So after some research, I thought I should add a pipe like so:

awk -F: '/label-uk|label-en-gb/ {print $2}'

But this returns duplicates for the apps that contain both terms, then I tried with two pipes, like so:

awk -F: '/label-uk/ || /label-en-gb/ {print $2}'

Both commands work, but both show duplicates.

Can awk return only the first matching term instead of both?

Thank you!

oguz ismail
  • 1
  • 16
  • 47
  • 69
5c0tt
  • 57
  • 6
  • 2
    Please add sample input (no descriptions, no images, no links) and your desired output for that sample input to your question (no comment). – Cyrus Feb 08 '21 at 17:35
  • Does this answer your question? [Use awk to find first occurrence only of string after a delimiter](https://stackoverflow.com/questions/15331259/use-awk-to-find-first-occurrence-only-of-string-after-a-delimiter) – xhienne Feb 08 '21 at 18:20
  • 3
    [Again](https://stackoverflow.com/q/66084273/1745001) you're asking for help to parse the output of a command but not showing us the output of the command so the answers you get could be completely inappropriate even if they do produce the output you expect. – Ed Morton Feb 08 '21 at 18:31

2 Answers2

2

By using the following, it will exit after first match (see the additional: exit)

... | awk -F: '/label-uk|label-en-gb/ {print $2; exit}'
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
karakfa
  • 66,216
  • 7
  • 41
  • 56
1

Try the following:

aapt dump badging App.apk | awk -F: '/label-uk|label-en-gb/ && fnd !=1 {print $2;fnd=1}'

Set a variable fnd to 1 when we print the first instance and then only print when fnd is not equal to 1.

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18