how to read fixed length flat file....

Hi Gurus,

Thanks in advance...

I am new to writing shell scripting and help me out reading a flat file with fixed length.

I have a fixed length flat file with storename(lenth 6) , emailaddress(lenth 15), location(10). There is NO delimiters in that file.

Like the following str00001.txt

StoreName emailaddress location


xxxxxxiiiiiiiiii@yahoo.com mmmmm
yyyyy aewwcb@gmail.com lllllllllllllllllllllllll

  •    [EMAIL="zzzz@email.com"]zzzz@email.com[/EMAIL]                    ujeuri
    

I have to read line by line in the flat file get the email address and location.and set it in a string

  1. Read line by line
  2. Set email address and location in a variable

String email = "iiiiiiiiii@yahoo.com�;
String loc = � mmmmm�;

Check out this post: parsing a string in a shell script

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

******************************************************

$> echo "xxxxxxiiiiiiiiii@yahoo.com mmmmm"| awk '{print substr($1,7)}'
iiiiiiiiii@yahoo.com
$> echo "xxxxxxiiiiiiiiii@yahoo.com mmmmm"| awk '{print $NF}'
mmmmm

# putting it to variables:

String_email=`awk '{print substr($1,7)}' infile`
String_loc=`awk '{print $NF}' infile`

This will give a list of strings in each varaible. Maybe you want to handle it as arrays or read through it via while/read and parse it or just work it completely in awk, idk.