General discussion

Locked

Lenght of data

By vavazquez652 ·
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

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Gary_W In reply to Lenght of data

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

Collapse -

by ghislain.levesque In reply to Lenght of data

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

Collapse -

by vavazquez652 In reply to

Both solutions were great and helped me.

Collapse -

by vavazquez652 In reply to Lenght of data

This question was closed by the author

Back to Linux Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums