How to parse the string and get elements form it

input string: foo_20130612_15_25_46_bar01_02

expected output: 20130612

echo “foo_20130612_15_25_46_bar01_02” | awk -F’_’ ‘{print $2}’

echo “foo_20130612_15_25_46_bar01_02” | cut -d’_’ -f2

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.