Regex a field from string; sed and Linux

How can I use sed to extract the value of the serializedlength, 3600605 in this case, from the following string?

Value at:0x7f36dda576f0 refcount:1 encoding:skiplist serializedlength:3600605 lru:1837863 lru_seconds_idle:20

If not sed, when how?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I do not believe sed is what you are looking for as this is commonly used to modify strings, I would alternatively recommend awk or cut.

I placed your string into a file to provide an example on how I would extract the required data if being piped from another program.

My first examples pull serializedlength and the value out.

cat /tmp/eetmp | cut -f 5 -d " "

cat /tmp/eetmp | awk -F " " '{ print $5 }'

awk -F " " '{ print $5 }' < /tmp/eetmp

My second examples pull just the value of serializedlength.

cat /tmp/eetmp | awk -F " " '{ print $5 }' | awk -F ":" '{ print $2 }'

cat /tmp/eetmp | cut -d " " -f 5 | cut -d ":" -f 2

awk -F " " '{ print $5 }' < /tmp/eetmp | cut -d ":" -f 2

as you can see there are many different variants on how to do this, if you require any further help please let me know. - the 5 and 2 indicate which delimited values I require.

I hope the above helps.

Kind Regards,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
How about grep?


echo "Value at:0x7f36dda576f0 refcount:1 encoding:skiplist serializedlength:3600605 lru:1837863 lru_seconds_idle:20" | grep -iPo '(?<=serializedlength:)\d+'

Open in new window

Tested on GNU grep 2.14.
brothertomAuthor Commented:
Thank you very much - the double cut works nicely for me :)

brothertomAuthor Commented:
kaufmed - thanks for the grep example, however there appears to be no -P option in my grep version - looks interesting though.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.