0

This is the command what i run.

ldap="$(ldapwhoami -x -H ldap://ABC.example.org -D "$user" -w "$pass")"

This is the output result:

u:ABC\1234567

May i know how to get the expected output ? like this 1234567

Thanks

XYZ
  • 13
  • 4
  • 4
    `your command | cut -d'\' -f2` – Red Cricket Sep 28 '18 at 01:21
  • Possible duplicate of [How to remove all non-numeric characters from a string in BASH?](https://stackoverflow.com/questions/19724531/how-to-remove-all-non-numeric-characters-from-a-string-in-bash) – Sparrow Sep 28 '18 at 03:26

2 Answers2

1

1st Solution: Could you please try following.

echo "u:ABC\1234567" | awk -F'\' '{print $NF}'

OR

your_command | awk -F'\' '{print $NF}'

2nd solution: using awk's sub method.

your_command  | awk '{sub(/.*\\/,"")} 1'
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
0
echo "u:ABC\1234567" | sed "s/[^0-9]//g"

There is a way with SED.

Sparrow
  • 146
  • 10