2

I want Output of this file only

AVDDPLL1V8
AGNDPLL1V8
DVDDPLL1V1
DGNDPLL1V1 

Here is my input:

6.1.2 Power and Ground Pins
             The following table describes the power and ground pins for the PLL.


             Table 5: Power and Ground Pins
                  Pin Name                                                Description
                                    Analog power pin. This pin provides the power supply for the sensitive analog
                AVDDPLL1V8
                                    blocks of the PLL.
                                    Analog ground pin. This pin provides the ground for the sensitive analog blocks
                AGNDPLL1V8
                                    of the PLL.
                                    Digital power pin. This pin provides power supply for the digital circuits in the
                DVDDPLL1V1
                                    PLL.
                DGNDPLL1V1          Digital ground pin. This pin provides ground for the digital circuits in the PLL.
  • Thanks for answers. Some times I may have VSSA or VDDA also instead of DVDDPLL1V1 in file. At that time suggitions given by you will not work. It is ouput of table pinname and decription in a pdf (we did pdf2text converter). Required names are always under Pin Name. In PDF pin names and description are always varies. But table size will not varie. Can you get by using theese inputs?????? Thanks in advance, Venu – user82398 Aug 29 '14 at 11:45
0
sed -n 's/^ *\([[:upper:]0-9]\{10,\}\).*/\1/p'

That will print the first word on a line if the word is comprised of at least 10 consecutive characters that are only uppercase letters and/or numbers. Nothing else is printed.

Run on your example data its output is:

AVDDPLL1V8
AGNDPLL1V8
DVDDPLL1V1
DGNDPLL1V1
2

One way to do it:

$ awk '$1 ~ /^[[:upper:]]+[0-9]+/ {print $1}' file
AVDDPLL1V8
AGNDPLL1V8
DVDDPLL1V1
DGNDPLL1V1

Explanation

We only check first field of each line, if it start with ^ one or more uppercase characters [[:upper:]]+, follow by one or more numbers [0-9]+, just print it.

With your input, I assume that after uppercase characters is one ore more numbers.

2

Try the below grep command to print all the alphanumeric characters,

$ grep -oP '[A-Z0-9]*[A-Z][0-9][A-Z0-9]*' file
AVDDPLL1V8
AGNDPLL1V8
DVDDPLL1V1
DGNDPLL1V1
1

If your problem with the existing answers is that they don’t find words that consist only of capital letters (with no digits), then we can adapt Gnouc’s answer like this:

awk '$1 ~ /^[[:upper:]0-9]+$/ {print $1}'

or

awk '$1 ~ /^[[:upper:][:digit:]]+$/ {print $1}'

This differs from his solution in that

  • By putting the digits ([0-9] or [:digit:]) into the brackets with the capital letters ([:upper:]), we require only that each matching character is either a capital letter or a digit, where Gnouc’s current answer requires at least one of each.
  • By adding the $, we make sure that the entire first word is composed of capital letters and/or digits.  Without it, The, Table, Pin, and Analog would match because they begin with a capital letter.

This would match a plain number (e.g., 612) if it is the first “word” (i.e., the first sequence of non-blank characters) on a line. To avoid this, do

awk '$1 ~ /^[[:upper:]][[:upper:]0-9]*$/ {print $1}'

or

awk '$1 ~ /^[[:upper:]][[:upper:][:digit:]]*$/ {print $1}'

which require the “word” to begin with a letter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.