Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Prevent word splitting with file with spaces in name

$
0
0
Hello,

I have a script that "validates" a ZIP file that look like this

Code:

AAA_20120801.zip =>
x~back end~20120801.TXT
y~time in~20120801.TXT
z~heat_chamber~20120801.TXT
AAA_20120801.ctl

My task is to compare its contents (i.e the list of files contained inside) with the control file that is provided inside the ZIP file itself.

Since we've started receiving files with spaces in their name, I prevented the OS from word splitting file names when I view the ZIP's contents like so

Code:

FIRST_Array=(); while read length date time filename; do FIRST_Array+=( "$filename" ); echo -e "$filename";
done < <(/usr/bin/unzip -qql AAA_20120801.zip)

When I try to do the same with the control file,

Code:

SECOND_Array=(); while read filename; do SECOND_Array+=( "$filename" ); echo -e "$filename"; done < <(/usr/bin/unzip -p AAA_20120801.zip AAA_20120801.ctl )
SECOND_Array() correctly outputs the file names in the control files but it also output the file sizes listed in the control file
Code:

x~back end~20120801.TXT 2KB
y~time in~20120801.TXT 2KB
z~heat_chamber~20120801.TXT 2KB

and my array comparison (diff -q) fails.

I tried adding this bit of Awk() code to remove the file size field but it brings word splitting back!

Code:

SECOND_Array=(); while read filename; do SECOND_Array+=( "$filename" ); echo -e "$filename"; done < <(/usr/bin/unzip -p AAA_20120801.zip AAA_20120801.ctl |awk '{print $1}')

How can I remove the file size info and prevent word splitting? Any ideas?

Thank you.

Viewing all articles
Browse latest Browse all 13329

Trending Articles