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!

How to do get the first 10 characters of a parameter value

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
0
0
US
I need to read the value of a parameter in a file. If the number of characters in this value is more than 10 then I need to take the first 10 characters of this value(something like a substring(value,1,10)) and substitute it as its value.

e.g.,
TABLENAME=EMPLOYEE_RECORD - Here the value of TABLENAME(i.e., EMPLOYEE_RECORD) contains 15 characters, hence we need to change the value of TABLE to the first 10 characters. Hence the value will become TABLENAME=EMPLOYEE_R.

If the number of characters in the value for this variable it 10 or less, then we need to leave it alone.
e.g.,
TABLENAME=DEPARTMENT
then
TABLENAME=DEPARTMENT

I would appreciate if someone could tell me how to do this in a shell script.

Thanks,
P
 
man expr (the substr operator)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi

mpramods said:
something like a substring(value,1,10)
If you have [tt]bash[/tt], it can do what you specified.
Code:
[blue]master #[/blue] s="abcdefghijklmnopqrstuvwxyz"

[blue]master #[/blue] echo "$s"
abcdefghijklmnopqrstuvwxyz

[blue]master #[/blue] echo "${s:0:10}"
abcdefghij

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top