The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-2009
pssandeep pssandeep is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 34
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
  #2 (permalink)  
Old 10-12-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,163
Always helps to see the actual script and the actual error message.

Two points:

Quote:
Folder = '/zzz/xxx/yyy'
file = 'abc def 123.txt'
No spaces before/after the equals sign
Code:
Folder='/zzz/xxx/yyy'
file='abc def 123.txt'
Which quotes?
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"
  #3 (permalink)  
Old 10-12-2009
thegeek thegeek is online now
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 434
This might help you.

Single versus double quotes in BASH | WiredRevolution.com
  #4 (permalink)  
Old 10-12-2009
pssandeep pssandeep is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 34
Thanks for the Help
"$Folder"/"$file" this serve the purpose

I am giving in other way

Thanks again for quick response

Cheers,
San
  #5 (permalink)  
Old 10-15-2009
sol10admin sol10admin is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 4
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
  #6 (permalink)  
Old 3 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 227
best way to retrieve a variable is to use the below syntax:-

Code:
"${variable_name}"
BR
  #7 (permalink)  
Old 2 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 227
the "${Varname}" is available in bash only.

---------- Post updated at 07:19 AM ---------- Previous update was at 07:18 AM ----------

Quote:
Originally Posted by ahmad.diab View Post
the "${Varname}" is available in bash only.
sorry not only in bash but also in KSH.
BR

---------- Post updated at 07:22 AM ---------- Previous update was at 07:19 AM ----------

kindly find some details and example below:-

Code:
Quoting means just that, bracketing a string in quotes. This has the effect of protecting special characters in
the string from reinterpretation or expansion by the shell or shell script. (A character is "special" if it has an
interpretation other than its literal meaning, such as the wild card character -- *.)
bash$ ls -l [Vv]*
-rw-rw-r-- 1 bozo bozo 324 Apr 2 15:05 VIEWDATA.BAT
-rw-rw-r-- 1 bozo bozo 507 May 4 14:25 vartrace.sh
-rw-rw-r-- 1 bozo bozo 539 Apr 14 17:11 viewdata.sh
bash$ ls -l '[Vv]*'
ls: [Vv]*: No such file or directory
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0