Help with reading directory paths with spaces from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with reading directory paths with spaces from a file
# 1  
Old 08-03-2017
Help with reading directory paths with spaces from a file

Hi I want to know how to handle the spaces in the below scenario.
I have a file (CON_zip_path_1.txt) which has some directory paths with spaces in directory names . My requirement is to unzip these zip files to
another path. Please see the code below and the error.

CON_zip_path_1.txt file contents -there are 9 directory path records with spaces in folder names:
Code:
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218812.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218800.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218600.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218563.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218553.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218556.zip
 /Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218559.zip
 /Contract Workspaces/2017/May/CW221xxxx/CW22184xx/CW2218471.zip
 /Contract Workspaces/2017/May/CRW221xxxx/CRW22184xx/CRW2218451.zip

Code:
 src_path=/informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332 ;
 while read line; do    
echo $src_path$line
unzip $src_path$line -d $src_path/Contract\ Workspaces
done < $src_path/CON_zip_path_1.txt ;

error output :
Code:
 /informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332/Contract Workspaces/Contract Repository/TCW1000 to TCW9999/TCW1000 to TCW1999/TCW1000 to TCW1099/TCW1000 to TCW1009/CW2218812.zip
unzip:  cannot find or open /informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332/Contract, /informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332/Contract.zip or /informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332/Contract.ZI

P.
# 2  
Old 08-03-2017
Code:
src_path=/informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332 ;
dos2ux < "$src_path/CON_zip_path_1.txt" | while read line; do
echo "$src_path$line"
unzip "$src_path$line" -d "$src_path/Contract Workspaces"
done  < $src_path/CON_zip_path_1.txt ;

Moderator's Comments:
Mod Comment Please don't modify posts that have been referred to by others, pulling the rug from under their feet.
Undid rdrtx1's redirection removal by striking it through.

Last edited by RudiC; 08-08-2017 at 06:53 AM..
This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 08-03-2017
Quote:
Originally Posted by rdrtx1
Code:
src_path=/informatica/apps/logs/fin/ote/SrcFiles/Source/Contracts20170706092332/Contracts20170706092332 ;
dos2ux < "$src_path/CON_zip_path_1.txt" | while read line; do
echo "$src_path$line"
unzip "$src_path$line" -d "$src_path/Contract Workspaces"
done < $src_path/CON_zip_path_1.txt ;

To be safe in case spaces, tabs, other IFS characters are later added to the value assigned to the src_path variable, I think you should also quote the expansion of src_path in the redirection at the end of the loop as well as in all places where it is expanded inside the loop:
Code:
done < "$src_path"/CON_zip_path_1.txt ;

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 08-07-2017
Thank You so much Don
# 5  
Old 08-07-2017
The suggestion feeds the loop from a pipe (at the beginning of the loop) *and* from the file (redirection at the end of the loop). Does not make sense. Bash silently ignores the pipe.
Please add the "quotes" but omit the dos2ux ... | !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

' for reading (No such file or directory)

1.1 Solaris 10 8/07 s10s_u4wos_12b SPARC 1.2 Patch: 127714-03 Obsoletes: Requires: 120011-14 Incompatibles: Packages: SUNWsshcu, SUNWsshdu, SUNWsshu Patch: 128253-01 Obsoletes: Requires: Incompatibles: Packages: SUNWsshcu Patch: 126630-01 Obsoletes: Requires: Incompatibles: Packages: SUNWtcsh 1.3... (3 Replies)
Discussion started by: alvinoo
3 Replies

2. OS X (Apple)

File paths with spaces in a variable

Hi all my very first post so go easy on me!! I am trying to build a very simple script to list a file path with spaces in. But I can't get around this problem. My script is as follows: #!/bin/bash X="/Library/Users/Application\ Support/" LS="ls" AL="-al" $LS $AL $X The response I... (5 Replies)
Discussion started by: tillett22
5 Replies

3. Shell Programming and Scripting

reading file paths from a text file

Hello all, I am new to scripting and here is what I want to get done. I need to run some processing on many files. I have a whole bunch of files among which there are a few that I am interested in. What I need to do is to write a script which reads the file paths from a text file. line by... (1 Reply)
Discussion started by: pavo-cristatus
1 Replies

4. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

5. UNIX for Dummies Questions & Answers

cat a list of directory paths only to a file

Hi! I would like to funnel a series of directories and subdirectories into a text file. This is the output I would like to see from a find command: /mypath/ABC_01/VISIT_01 /mypath/ABC_01/VISIT_02 /mypath/ABC_01/VISIT_03 /mypath/ABC_02/VISIT_01 /mypath/ABC_03/VISIT_01 I've tried: find... (2 Replies)
Discussion started by: goodbenito
2 Replies

6. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

7. UNIX for Dummies Questions & Answers

Unable to use mimesender to send attachments with spaces in the file names / paths

Hello, I found the mimesender multiple attachment emailing shell script in the FAQ of these forums, and I have been able to use it to send multiple files, but only if they don't have spaces in their file name or path. When I attempt to send a file with spaces in it's name, enclosed... (0 Replies)
Discussion started by: rsmorra
0 Replies

8. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies

9. Shell Programming and Scripting

prob with spaces in reading a file

i have a file in unix having data like cat dog (having spaces in the beginning) when i read it in a shell script cat file_name |while read line do echo $line done it will print cat dog spaces at the beginning are removed.... i dont want these spaces to be... (2 Replies)
Discussion started by: Amardeep
2 Replies

10. UNIX for Dummies Questions & Answers

reading directory for most recent file?

Dear All, I'm trying to write a script that searches thru a directory looking for a most recent file and then scp that file. I have the scp working, but I don't know how to browse the directory and select the most recent file. The file name includes a date & time stamp (e.g.... (3 Replies)
Discussion started by: duncan_glover
3 Replies
Login or Register to Ask a Question