Discussion Locked

Lenght of data

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can i identify the lenght of a data, by example I have a file with the following information:

HMX 01000 01001
RMX 01005 01005
...
...
...
FMX 0005000 5000
FMX 0005008 5010
FMX 0005020 5020

As you can see most of the registers (data) have the same lentgh in the last two columns, but how can I identify the length of this data: 0005000.

I need to read the file and identify that problem.

I will reallly appreciate your help to solve this problem.

Thank You

Best Regards

4 replies

by gary_w

I assume that since this is posted in the UNIX forum that you are looking for a shell script solution. Here's one way, although it's a tad ugly ('data' is a file containg records as you described):

integer length
cat data | while read line
do
set $line
length=`echo $2|wc -c`
length=`expr $length - 1`
echo $length
done

I'm sure some slick perl programmer can come up with a much better way.

Gary

by ghislain.levesque

Here is a little script that will print to you a line number + the line that column 2 & 3 which has a different lenght.

num=1
cat test_file|while read line
do
col2=`echo $line|cut -d" " -f2|wc -c`
col3=`echo $line|cut -d" " -f3|wc -c`
if [ "$col2" != "$col3" ]
then echo "line number $num is invalid"
echo $line
fi
num=`expr $num + 1`
done

This discussion is closed to new replies.