Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Mar 2002 15:30:03 -0700 (MST)
From:      Warren Block <wblock@wonkity.com>
To:        Eric Boucher <eric_boucher60@yahoo.com>
Cc:        FreeBSD <freebsd-questions@FreeBSD.ORG>
Subject:   Re: exact length of a line in a file with the read command
Message-ID:  <Pine.BSF.4.21.0203311523540.67351-100000@wonkity.com>
In-Reply-To: <20020331202713.66909.qmail@web9401.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 31 Mar 2002, Eric Boucher wrote:

> I want to know the exact length of each line in a
> file. But it seems that when the file begin or end
> with a space caracter of a tab caracter, the "read"
> command in bourne shell delete them and return me only
> what begin with a letter and end with a letter. So
> when I try to know the exact length of a file (I tried
> with both lenght command from "expr" and "nawk"). So
> if for example, a line is like this (note: <space>
> mean the real space caracter and <tab> the tab
> caracter)
> <space>toto<tab>
> the read return me only:
> toto
> which is of length = 4
> but it is suppose to be of length = 6
  
This just worked for me:

#!/bin/sh
IFS=""
echo "Enter a string"
read tester
echo $tester
echo ${#tester}

If a shell script is going to be non-trivial, I just use Perl.

-Warren Block * Rapid City, South Dakota USA



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0203311523540.67351-100000>