Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy One - First 8 Characters Only Please 3

Status
Not open for further replies.

jmarkus

Technical User
Oct 15, 2002
124
0
0
CA
How do I get only the first 8 characters of a string to print?

I'm trying:
echo "12345678.msytring.ext" | sed '/[A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9][A-Z,a-a,0-9]/';

But I'm obviously not doing it right.

Thanks,
Jeff
 
echo "$string" | cut -c1-8
echo "$string" | sed 's!^\(.\)\{8\}.*!\1!'
echo "$string" | awk '{print substr($0,1,8)}'
In ksh:
typeset -L8 newstring="$string"

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
echo "12345678abcd" | awk '{ print substr($0, 0, 8) }'

--
-- GhodMode
 
ksh93 also supports:

#var=1234567890
#print ${var:0:3}
#123
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top