Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Nov 2002 03:29:17 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Brian Henning <b1henning@hotmail.com>
Cc:        questions@freebsd.org
Subject:   Re: shell script
Message-ID:  <20021122012917.GD15933@gothmog.gr>
In-Reply-To: <OE62iJCAgn5yIVqVWrx0000bf2c@hotmail.com>
References:  <OE62iJCAgn5yIVqVWrx0000bf2c@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-11-21 14:10, Brian Henning <b1henning@hotmail.com> wrote:
> I have a simple shell script problem. if i have a file name with a
> space in the name the following script doesn't get the entire name.
> The for loop conditional statement below stops for spaces or new
> lines... i would like it to stop for just new lines. is there a way
> to do that with shell script. how can i change the condition in the
> for loop to do that?

> #!/bin/sh -x
> # sh size.sh /smb/dc input.txt
>
> PATH=$1
> INPUT=$2
>
> for i in `/bin/cat ${INPUT}`; do
>     echo "in loop"
>     FILE=`echo $i | /usr/bin/awk -F: '{ print $1 }'`
>     SIZE=`echo $i | /usr/bin/awk -F: '{ print $2 }'`
>
>     echo "${FILE}
> done
> exit 0;

You don't really need to write the loop in shell code for printing
everything up to the first ':' (which is what your shell script
apparently tries to do by passing each line to awk(1).  Just pass the
input.txt file to awk.  The following will work correctly:

	awk -F: '{print $1}' < input.txt


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?20021122012917.GD15933>