1

I have a string like basedir=/cp/osp/peaker/1543.23. here i want to extract 1543.23, in linux script, could someone tell me how to do this here.

May be using sed, regex, i was unable to do. here i want 1543.23 (so i want number and special character . also).

0

1 Answer 1

2

You could use awk. Something like

echo $basedir | awk 'BEGIN {FS="/"};{print $NF}'

That begins by setting the field separator (FS) to "/" and then printing the last field.

Sign up to request clarification or add additional context in comments.

2 Comments

Its returning 20 ports, i want only one listening port, i gave the process id also.
You asked how to extract a number from a string... where did you say anything about ports, process ids or (in fact) any processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.