[Gllug] bash string confusion
Russell Howe
rhowe at siksai.co.uk
Wed Jul 6 15:46:48 UTC 2005
On Wed, Jul 06, 2005 at 04:34:58PM +0100, Craig Millar wrote:
> Am trying to write a small bash script to check which stock items in our
> inventory have not yet been illustrated. So, I get a dump of stock numbers
> out of the database (filemaker - won't get started on that) and compare them
> to the numbered images in the folder. Only, it is not working and I am
> absolutely stumped:
>
> for i in `cat photo.txt`; do
> if test ! -e "$IMAGEDIR/$i.jpg" ; then
> echo $i >> unillustrated.txt
> fi
> done
If you're OK with it being bash-only, you can do this:
for item in $(< photo.txt); do
[ -f "$IMAGEDIR/$item.jpg" ] || echo "$i" >> unillustrated.txt
done
> It returns all the records. As I know there are several thousand photographs
> in the image folder, this is definitely not correct.
>
> So, I echo the resultant test using
>
> j="$i.jpg"; echo $j
>
> in the for loop and too my utmost surprise it is returning the image names
> with the .jpg suffix at the beginning, for example: .jpg0
There is probably a carriage return, so what you are seeing is something
like this:
xxx0<cr>.jpg
Where the <cr> causes the cursor to jump to the start of the line and
overprint.
> If I pipe the output to less, I get something sort of resembling what I am
> after, for eg: 59034^M.jpg - whither the ^M? Have opened up the file in vi -
> sometimes filemaker throughs up all sorts of strange characters - can't see
> any strange line breaks or the file though - certainly no ^Ms when i tried to
> remove them.
Try dos2unix on the file. Maybe it has DOS line endings?
--
Russell Howe | Why be just another cog in the machine,
rhowe at siksai.co.uk | when you can be the spanner in the works?
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list