![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing blank spaces, tab spaces from file | NARESH1302 | Shell Programming and Scripting | 3 | 08-07-2009 11:18 AM |
| how to append spaces(say 10 spaces) at the end of each line based on the length of th | prathima | UNIX for Dummies Questions & Answers | 17 | 01-28-2009 04:10 PM |
| need help in replacing spaces in a file | sais | Shell Programming and Scripting | 7 | 10-06-2008 09:24 AM |
| Directories with spaces in name - looking for help with questions in that issue | alex_5161 | Shell Programming and Scripting | 2 | 02-29-2008 03:49 PM |
| Strip leading and trailing spaces only in a shell variable with embedded spaces | jerardfjay | Shell Programming and Scripting | 6 | 03-07-2005 02:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
||||
|
Spaces in File Name issue
Hi,
I have a small issue while using variables for a file name in UNIX. I have file name like "abc def 123.txt" Folder will be in /zzz/xxx/yyy I created 2 variables Folder = '/zzz/xxx/yyy' file = 'abc def 123.txt' While using this in grep command i am getting an error i used like '$Folder"/"$file' could u quote me where i am going wrong.I think small tweak will serve the purpose. But i am missing it somewhere Thanks in Advance, San ![]() |
|
||||
|
Always helps to see the actual script and the actual error message.
Two points: Quote:
Code:
Folder='/zzz/xxx/yyy' file='abc def 123.txt' Anything between single quotes is protected from the shell and no substitution will take place. You need double quotes to preserve the spaces but definitely not single quotes when there is a variable involved. Code:
grep "mystring" "$Folder"/"$file" |
|
||||
|
|
|
||||
|
I can't take credit for the meat and potatoes of this script, but I can't remember who gave it to me and from what forum. But it does replace : in file names and replaces them with a - and then changes the file extention to dat. This might work for you. I hope this helps. I use this to take files from UNIX and make them readable in DOS, and then clean up after itself.
![]() Code:
#!/bin/csh
cd /home/files
# cp $1 /tmp
cp *DH /tmp
cd /tmp
ls -1 *.DH > /tmp/DH.list
set filelist=`cat /tmp/DH.list`
foreach x ($filelist)
set newname=`echo $x|sed 's/:/-/g'`
echo $newname
cp $x /tmp/$newname
end
cd /tmp
ls -1 *.DH > /tmp/DH1.list
set filelist=`cat /tmp/DH1.list`
foreach x ($filelist)
set newname=`echo $x|sed 's/DH/dat/g'`
echo $newname
cp $x /tmp/$newname
end
rm *:*:*.dat
zip dh *.dat
allocate floppy_0
rm -r /floppy/floppy0/*
cp dh.zip /floppy/floppy0
deallocate floppy_0
rm *.DH
rm *.dat
rm dh.zip
rm DH*
Subsitute your file names and spaces. Last edited by bakunin; 2 Weeks Ago at 06:26 AM.. Reason: added code-tags |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|