- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- urgent : Korn shell programmig using set
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2001 07:19 AM
02-15-2001 07:19 AM
urgent : Korn shell programmig using set
I am using set array option to store the records into fields and then compare.
What exactly happening is when the
field contains null spaces. the array is truncating it.
For ex. when the field contains the value
"1 ", the array truncates the remaining spaces after 1. But i want to compare as it is with out truncation using
set -A option.
How to avoid truncation of fields with trailing null spaces ?
Because of this truncation i am getting wrong results.
One more thing what i need is,
when the field value is more than expected length, i have to truncate to specified length.
For ex.
set -A fields2 $(print "$line2" | tr "\|" " "
fieldlen=`expr length "${fields3[$y]}"`
if [ $fieldlen -gt 12 ]
then
fields2[$y]=`expr substr "${fields2[$y]}" 1 12`
else
:
fi
Can i assign the value to array of strings this way ?
How do i reassign the value to an array ?
I have given below the sample code.
####Sample Code ####
exec 3 < file1
exec 5 < file2
while read -u3 line1
do
no_of_fields=`echo $line1" | awk '{ FS = "|" } { print NF }`
set -A fields1 $(print "$line1" | tr "\|" " ")
while read -u5 line2
do
set -A fields2 $(print "$line2" | tr "\|" " "
count=$no_of_fields
cmpfile3=0
y=0
while [ $count -gt 0 ]
do
fieldlen=`expr length "${fields3[$y]}"`
if [ $fieldlen -gt 12 ]
then
fields1[$y]=`expr substr "${fields1[$y]}" 1 12`
fields3[$y]=`expr substr "${fields3[$y]}" 1 12`
else
:
fi
........
#########
Awaiting your reply.
Thanks
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2001 07:38 AM
02-15-2001 07:38 AM
Re: urgent : Korn shell programmig using set
> To preserve spaces as a legitimate field, change your IFS variable in your script, like:
IFS=: #...changes the inter-field-separator from the standard space to the colon character.
> To change the value of an array element, do, for example:
ARY[3]=" XYZ "
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2001 07:41 AM
02-15-2001 07:41 AM
Re: urgent : Korn shell programmig using set
First question: this is what I have:
$ set -A arrTest " 1 "
$ echo --${arrTest[0]}--
--1--
$ IFS=""
$ set -A arrTest " 1 "
$ echo --${arrTest[0]}--
-- 1 --
$ unset IFS
Is that what you desire??
Do not forget to unset IFS after you're ready with it. For more info on IFS, check out the sh-posix manpage.
Hope this helps,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2001 07:50 AM
02-15-2001 07:50 AM
Re: urgent : Korn shell programmig using set
For your field length problem, you might try to substr before storing the variables into the array.
set -A fields $(echo $line | awk '{ for (i=1;i<=NF;i++) print substr($i,1,12) }')
This should limit every word on $line to 12 characters.
Hope this is what you want,
Rik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2001 08:29 AM
02-21-2001 08:29 AM
Re: urgent : Korn shell programmig using set
Thanks for your help in resolving the problem.
-Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2001 10:17 PM
02-21-2001 10:17 PM
Re: urgent : Korn shell programmig using set
It's nice to say 'Thanks' but it would be a lot nicer if you assigned points to the people who spent some time (or a lot of) to help you.
Thanks for them,
No point for me please !
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2001 08:24 AM
02-22-2001 08:24 AM
Re: urgent : Korn shell programmig using set
A world of posibilities:
From man sh-posix
& typeset [{-|+}LRZfilrtux[n]] [name[=value]]...
name=value [name=value]...
Assign types and a value to a local named parameter name. See
also the export special command. Parameter assignments remain in
function, create a new instance of the parameter name. The
parameter value and type are restored when the function
completes.
The following list of attributes can be specified. Use + instead
of - to turn the options off.
-L Left justify and remove leading blanks from value. If n is
nonzero, it defines the width of the field; otherwise, it is
determined by the width of the value of first assignment.
When name is assigned, the value is filled on the right with
blanks or truncated, if necessary, to fit into the field.
Leading zeros are removed if the -Z option is also set. The
-R option is turned off. Flagged as leftjust n.
-R Right justify and fill with leading blanks. If n is
nonzero, it defines the width of the field; otherwise, it is
determined by the width of the value of first assignment.
The field is left-filled with blanks or truncated from the
end if the parameter is reassigned. The -L option is turned
off. Flagged as rightjust n.
-Z Right justify and fill with leading zeros if the first
nonblank character is a digit and the -L option has not been
:-))