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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncating characters from the end of fields 1

Status
Not open for further replies.

ianholmes

Programmer
Mar 24, 2001
61
GB
Hi
I have 2 fields X and Y, both 8 characters long.
When X is passed to my script, the last 1 or 2 characters can be corrupted.
I need to compare X with Y, and pass if
X = Y, or
chars 1...7 of X = chars 1...7 of Y or
chars 1...6 of X = chars 1...6 of Y.

I thought something like

if [[ ${X%?} != ${Y%?} && $X != ${Y%?} ]]
then error
etc etc

would work, but how do I drop off the last 2 chars ?

Hope someone can help.
Please : no awk, it's just not practicable.
 
Try something like this:
Code:
typeset -L6 x6=$X
typeset -L6 y6=$Y
[ "$x6" != "$y6" ] && echo "Error X='$X', Y='$Y'"

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top