How to get the values of multipledot(.) separated fields?

Hello,

I have a file which has the following contents :

thewall............0000000000200000  kmemfreelater......0000000000000000
kmemgcintvl........0000000000000002  kmeminuse..........00000000223411C0
allocated..........0000000029394000  bucket.......... @.F1000A02800C2158

The mentioned values are the hexadecimal values. I need to get the values of thewall and allocated respectively. The problem here is that there can be n number of dots(.) and I am unable to retrieve the respective hexadecimal values because number of dots might vary from server to server.

Please help. Thanks a lot :slight_smile:

Rahul

Try something like:

sed -n 's/.*thewall[.][.]*\([^[:blank:]]*\).*/\1/p' file
1 Like

Hello Can you please explain how the above command works. It worked fine for me :slight_smile:

  1. sed -n (don't print unless we say so)
  2. s/.*thewall[.][.]* (match anything followed by "thewall" followed by one dot followed by zero or more dots)
  3. \([^[:blank:]]*\) (match and capture anything that is not a blank/return)
  4. .* (match anything else)
  5. /\1/ (replace with captured match)
  6. p (print it)

You'd can use the -e option to sed to do multiple things, so you can repeat the construct for "allocated". There could be a problem if there are strings like "anotherthewall" or "somethingelseallocated".

1 Like

If it finds a line with "the wall" followed by at least one dot, then it replaces everything on the line, except the part after the dots, this is signified by

\([^[:blank:]]*\)

which means zero or more characters that are not a space. De escaped parentheses signify a nested subexpression, which is referenced in the replacement part by \1 .
The -n option means do not print, while the p-flag at the end means "print if the substitution was successful"

1 Like