Computing.Net > Forums > Unix > parsing using Korn

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

parsing using Korn

Reply to Message Icon

Name: alimad
Date: March 30, 2007 at 14:49:58 Pacific
OS: Windows xp
CPU/Ram: 526
Product: Toshiba
Comment:

Hi, I need to know the best way to parse a textfile that contains the following text

00010000001M
00010000001Q
00040000001M

I would like to parse the first 8 characters and store it in a variable , then the next 3 characters and store it in a variable and so on and so forth, then loop to the next line. Can i do that in Korn?




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 30, 2007 at 23:00:07 Pacific
Reply:

Use the cut command to parse the text lines:

#!/bin/ksh

while read line
do
c=$(echo "$line" | cut -c1-8)
v=$(echo "$line" | cut -c9-11)
echo $c
echo $v
done < file



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: parsing using Korn

Random number generation using Korn www.computing.net/answers/unix/random-number-generation-using-korn/7806.html

Calling a .bat file using Korn scri www.computing.net/answers/unix/calling-a-bat-file-using-korn-scri/8291.html

Interactive Prompt PS1 with Korn www.computing.net/answers/unix/interactive-prompt-ps1-with-korn/7443.html