Skip to content

emka.web.id

Menu
  • Home
  • Indeks Artikel
  • Tutorial
  • Tentang Kami
Menu

Belajar Shell: Extract Digits From a String

Posted on April 29, 2012 by Syauqi Wiryahasana
How do I extract digits only from a given string under Bash shell? You can use the sed, grep and other shell utilities as follows: [sourcecode language="bash"] grep -o "[0-9]" <<<"input" grep -o "[0-9]" <<<"$var" grep -o "[0-9]" <<<"test123" grep -o "[0-9]" <<<"1Th5is is a test. 5" var="foo1bar2" output=$(grep -o "[0-9]" <<<"$var") echo "$output" grep -oE "[[:digit:]]{1,}" input.file [/sourcecode]
Seedbacklink

Recent Posts

TENTANG EMKA.WEB>ID

EMKA.WEB.ID adalah blog seputar teknologi informasi, edukasi dan ke-NU-an yang hadir sejak tahun 2011. Kontak: kontak@emka.web.id.

©2024 emka.web.id Proudly powered by wpStatically