Skip to main content
Fix broken quoting
Source Link
tripleee
  • 185.2k
  • 36
  • 295
  • 342

As pointed out by Zedfoxus here. A very clean method that works on all Unix-based systems. Besides, you don't need to know the exact position of the substring.

A="Some variable has value abc.123"

echo $A"$A" | rev | cut -d ' ' -f 1 | rev                                                                                            

# abc.123

As pointed out by Zedfoxus here. A very clean method that works on all Unix-based systems. Besides, you don't need to know the exact position of the substring.

A="Some variable has value abc.123"

echo $A | rev | cut -d ' ' -f 1 | rev                                                                                            

# abc.123

As pointed out by Zedfoxus here. A very clean method that works on all Unix-based systems. Besides, you don't need to know the exact position of the substring.

A="Some variable has value abc.123"

echo "$A" | rev | cut -d ' ' -f 1 | rev                                                                                            

# abc.123
Source Link
Cloudkollektiv
  • 13.7k
  • 4
  • 49
  • 77

As pointed out by Zedfoxus here. A very clean method that works on all Unix-based systems. Besides, you don't need to know the exact position of the substring.

A="Some variable has value abc.123"

echo $A | rev | cut -d ' ' -f 1 | rev                                                                                            

# abc.123