- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh: using of IFS ( check correct number of fields...
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
07-24-2013 07:41 AM
07-24-2013 07:41 AM
ksh: using of IFS ( check correct number of fields )
hello,
i many scripts we are using IFS to parse files with a loop. if the number of fields are correct, it is a powerful tool.
can i check the number of fields, before the loop starts ?
IFS : # .
example of parse 3 lines , line 3 has to many fields . also we have the issue, in ksh88 it is no problem, when to many fields exists ( the last fields were cutted ) and in ksh93 all supernumerous values (or fields) are in the last field.
i think this behaviour is correct .
example :
#!/usr/bin/ksh
echo "line1:field1#field2#field3##
line2:field1#field2#field3##
line3:field1#field2#field3# ##" | \
while IFS=# read field1 field2 field3
do
echo "field1=${field1} field2=${field2} field3=${field3}"
done
output:
field1=line1:field1 field2=field2 field3=field3
field1=line2:field1 field2=field2 field3=field3
field1=line3:field1 field2=field2 field3=field3#
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2013 06:08 PM
07-24-2013 06:08 PM
Re: ksh: using of IFS and read (check correct number of fields)
>in ksh88 it is no problem, when too many fields exists (the last fields were cut)
No, read puts them in the last field.
>field1=line1:field1 field2=field2 field3=field3
There are only three fields with trailing separators
>field1=line3:field1 field2=field2 field3=field3#
There are 4 fields. The separators and the 4th field are concatenated to field3. Any trailing separators are discarded.
I see no differences between dtksh and ksh88.