bashshellawk

Combine awk output field to corresponding integer


I'm trying to extract version numbers from lines in a file like below:

grep abc | awk '{print $3}' somefile and getting multiline output as:

7.2.5.200
7.3.4.100

I would like this output to be combined to an integer to use later as shown below:

expected output:

725200
734100

I tried using split function but looks like there is no join function in awk.
Any workaround for this would be much appreciated. Thanks in advance!


Solution

  • There are many ways to do this. One way, using awk:

    grep abc | awk '{ gsub(/\./, "", $3); print $3}' somefile
    725200
    734100
    

    but you hardly ever need to use grep when working with awk:

    awk '/abc/ { gsub(/\./, "", $3); print $3}' somefile
    725200
    734100