Search code examples
bashawkgrep

How to grep the number in text file?


i want to ask a question about 'awk' , example:

awk '{print $8}' tes.txt

output : size=21341,

but i only want to grep number "21341", can you give me solution about how to grep the number?


Solution

  • awk '{print $8}' tes.txt | grep -o '[0-9]*'
    output: 21341
    

    grep -o <regex> prints only the matched parts of matching lines, with each such part on a separate output line. See more detail.

    https://www.gnu.org/software/grep/manual/grep.html