Skip to main content
Inserted a missing hyphen in "0-9". Then did a trivial rewording because it requires 6 chars to be changed 8-)
Source Link

I would modify your own solution. Instead of deleting any $1 that doesn't match the required regexp, use grep to filter them out:

awk '{print $1}' /tmp/test | grep -iE '^[a-z0-9]{12}$'

Another alternativeAlternatively in pure sed:

sed 's/^\([a-zA-Z09]\Z0-9]\{12\}\)[ \t]\+.*/\1/' /tmp/test     

I would modify your own solution. Instead of deleting any $1 that doesn't match the required regexp, use grep to filter them out:

awk '{print $1}' /tmp/test | grep -iE '^[a-z0-9]{12}$'

Another alternative in pure sed:

sed 's/^\([a-zA-Z09]\{12\}\)[ \t]\+.*/\1/' /tmp/test

I would modify your own solution. Instead of deleting any $1 that doesn't match the required regexp, use grep to filter them out:

awk '{print $1}' /tmp/test | grep -iE '^[a-z0-9]{12}$'

Alternatively in pure sed:

sed 's/^\([a-zA-Z0-9]\{12\}\)[ \t]\+.*/\1/' /tmp/test     
Source Link
Joseph R.
  • 40.5k
  • 8
  • 114
  • 146

I would modify your own solution. Instead of deleting any $1 that doesn't match the required regexp, use grep to filter them out:

awk '{print $1}' /tmp/test | grep -iE '^[a-z0-9]{12}$'

Another alternative in pure sed:

sed 's/^\([a-zA-Z09]\{12\}\)[ \t]\+.*/\1/' /tmp/test