General discussion

  • Creator
    Topic
  • #2176859

    Lenght of data

    Locked

    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

All Comments

  • Author
    Replies
    • #3334903

      Reply To: Lenght of data

      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

    • #3331539

      Reply To: Lenght of data

      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

    • #3352487

      Reply To: Lenght of data

      by vavazquez652 ·

      In reply to Lenght of data

      This question was closed by the author

Viewing 2 reply threads