|
Home > Archive > Unix questions > February 2006 > working with .dat files
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
working with .dat files
|
|
|
| Hi,
I have the requirement as follows.
I'm trying to find the length of each rec in my .dat file. For this i'm
doing the following
for rec in `cat <filename>.dat`; do
echo ${#rec}
done
If the no of records or lines in the <filename>.dat file is suppose 10.
But, it's giving more than 10 echo messages and It's giving the wrong
output.
> cat <filename>.dat | wc -l
10
-----------------
is there any other way to deal with .dat file's or suggest me how can i
get each record in to the for loop.
How can deal with the EOL with cat.
The same is working fine with other files.
How can i solve this problem
thanks,
an
| |
| Philip Paeps 2006-02-13, 6:04 pm |
| anju <anjani.unix.help@gmail.com> wrote:
> I'm trying to find the length of each rec in my .dat file. For this i'm
> doing the following
You don't mention what your ".dat" files look like.
Usenet readers do not often include crystal balls...
- Philip
--
Philip Paeps Please don't email any replies
philip@paeps.cx I follow the newsgroup.
Machines that have broken down will work perfectly
when the repairman arrives.
| |
| Stephane CHAZELAS 2006-02-13, 6:04 pm |
| 2006-02-13, 12:42(-08), anju:
> Hi,
> I have the requirement as follows.
>
> I'm trying to find the length of each rec in my .dat file. For this i'm
>
> doing the following
>
>
> for rec in `cat <filename>.dat`; do
> echo ${#rec}
> done
[...]
Please don't multipost, you're message was already answered in
another newsgroup.
--
Stéphane
| |
| Chris F.A. Johnson 2006-02-13, 6:04 pm |
| On 2006-02-13, Philip Paeps wrote:
> anju <anjani.unix.help@gmail.com> wrote:
>
> You don't mention what your ".dat" files look like.
Irrelevant; the OP just wants the length of the lines. Besides,
whatever the file looks like, the script is incorrectly written.
> Usenet readers do not often include crystal balls...
They also don't like multiposting. I have replied in
comp.unix.misc.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
|
| Hi,
<filename>.dat file looks as below.
411990
20060103 153232
966966
20060103 153233
391828
20060103 153233
1103224
20060103 153234
846814
20060103 153234
850595
20060103 153235
972543
20060103 153236
985800
20060103 153236
653049
20060103 153236
977316
20060103 153237
Thanks in advance,
an
| |
|
| Thanks a lot .. I don't do again..
thanks,
an
| |
| Pascal Bourguignon 2006-02-13, 6:04 pm |
| "anju" <anjani.unix.help@gmail.com> writes:
> Hi,
> <filename>.dat file looks as below.
>
>
> 411990
>
>
> 20060103 153232
> 966966
>
>
> 20060103 153233
> [...]
> Thanks in advance,
And what does this mean?
It looks like you have fixed-length records, filled with
spaces. Perhaps spread on several lines, perhaps not, depending on how
you copy-pasted and what software you use to post news
If you are really lazy, it would have been more instructive to provide
an hex dump:
od -t x1 -a filename.dat |head -40
But if you want a useful answer, you'd better give us the real
description of the file format.
Assuming that the filename.dat is a text file, that is, it's a file of
lines terminated by LF containing ASCII characters, the answer would be:
while read line ; do echo ${#line} ; done < filename.dat
--
__Pascal Bourguignon__ http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink.
| |
|
| Thanks a lot Pascal.
I got the thing..
|
|
|
|
|