atil thakor
atil thakor

Reputation: 13

How do i Extract integer value from a string in Unix

when i type this command /usr/local/afs7/bin/afs_paftools -a about.afs | grep TOTAL_DOCUMENTS

I get a result

TOTAL_DOCUMENTS = 74195

How i can extract the integer number(74195) after = using grep command

Upvotes: 0

Views: 1565

Answers (2)

Jotne
Jotne

Reputation: 41446

If there are no space:

TOTAL_DOCUMENTS=74195

Use this awk

echo "TOTAL_DOCUMENTS=74195" | awk -F= '{print $NF}'
74195

Upvotes: 0

Fredrik Pihl
Fredrik Pihl

Reputation: 45634

One way is to use grep:

$ echo "TOTAL_DOCUMENTS = 74195" | grep -o '[0-9]\+'
74195

or since you know, that it's the last field, use awk:

$ echo "TOTAL_DOCUMENTS = 74195" | awk '{print $NF}'
74195

or just use awk for the lot:

your-command -a about.afs | awk '/TOTAL_DOCUMENTS/{print $NF}'

Upvotes: 2

Related Questions