Reading a file using sh with spaces in filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a file using sh with spaces in filename
# 1  
Old 02-27-2008
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 supportIDPS/SCM/windows_install/file groups/dds.fgl
341001e442a16435a4dca02ce0fb1fa6 supportIDPS/SCM/windows_install/file groups/default.fdf
a06707d4ff14b9718ad1a876689ae3ad supportIDPS/SCM/windows_install/file groups/inf.fgl
# 2  
Old 02-27-2008
Try the cut command.

With a space as fieldseperator you can print the 2nd and the 3th column. Check the manpage of cut.


Regards
# 3  
Old 02-27-2008
As told by Franklin52, you can use:

Code:
cut -f2- -d ' ' input_file

# 4  
Old 02-27-2008
I figured out two solutions:

Solution 1:
while read line ;do
CUT=`echo "$line" | sed 's/^.* //g'`
md5sum $CUT
done < INFPUT_FILE

Solution 2:
while read checksum file ;do
md5sum "$file"
done < INPUT_FILE

Thanks everyone
# 5  
Old 02-29-2008
Try searching for my posts - I gave some instructions about this.
But in short way:

USE:
"${variable}"
instead of
$variable
This User Gave Thanks to adderek For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: paul1234
4 Replies

2. UNIX for Advanced & Expert Users

How to get file from share drive when filename with spaces using samba client?

Hi Team, I am not able to get file name from shared drive when filename have spaces in it. following command i am using. filename="REP00105 - ABC XYZ (SCM)_ 1.TXT" /hfx/opt/samba220/bin/smbclient \\\\${nt_host}\\${nt_share} ${NT_PASSWORD} -U${NT_USERNAME} -c "cd ${nt_directory}; prompt;... (1 Reply)
Discussion started by: Makarand Dodmis
1 Replies

3. Shell Programming and Scripting

Remove spaces in filename

Hi team, Here's a requirement for me. Here are the list of files i have in a unix directory. W 2 A D_2014.csv W 3 A D_2014.csv W 4 A D_2014.csv /home/kmani00-> uname -a AIX sliyyvxx 1 6 00F613E54C00 /home/kmani00-> The file names has to be without spaces as follows. W2AD_2014.csv... (1 Reply)
Discussion started by: kmanivan82
1 Replies

4. Shell Programming and Scripting

problem with spaces in filename

I have written a script to run ddrescue on a list of files. #!/bin/bash # # A script to rescue data recursively using ddrescue. srcDir=/damaged/hdd/movies/ #the source directory desDir=/new/hdd/movies/ #the destination directory... (2 Replies)
Discussion started by: colsinc
2 Replies

5. 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

6. Homework & Coursework Questions

Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data: I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no... (0 Replies)
Discussion started by: ds7202
0 Replies

7. Shell Programming and Scripting

spaces in filename

Hello I canīt find an answer to my problem. I am trying to tar some files with spaces #!/bin/sh files="/var/installer/server Config /var/installer/client user /var/installer/Svenskt Language /var/installer/GUI user Plugin /var/installer/Firefox Plugin" tar -czvf /tmp/files.tar.gz... (14 Replies)
Discussion started by: Lusen
14 Replies

8. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

9. UNIX for Dummies Questions & Answers

get the latest file by reading the date in the filename.

Hi, I grep for a pattern in a list of files. "grep -i -l $pattern *.datx*" it may give me n number of files. say for eg, it gives me 2 files. lock_eicu_20071228_00000000.dat_20071228_05343100 lock_eicu_20080501_00000000.dat_20080501_05343900 out of these 2 files I need to get the... (7 Replies)
Discussion started by: prsshini
7 Replies

10. 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
Login or Register to Ask a Question