LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-14-2004, 10:41 AM   #1
welby
LQ Newbie
 
Registered: Jul 2003
Posts: 7

Rep: Reputation: 0
Bash scripting - add a character to a line.


Occurred to me that I might have stuck this question in the wrong forum, so here it is again.

I use a script to generate a list of files for a backup process. The script find the files then ports the file names to a text file, which the rest of the script uses as a reference for the backup operation. Here is my problem:

The servers I'm backing up are a combination of Windoze and Novhell and both support long file names. When the script reads a long file name or directory with a space in it the file copy fails. I'm guessing that if I add quotation marks to the list of found files it will copy correctly, so the question is this: Can I have a script add quotation marks to the beginning and end of each line in a file? It can be done either as a separate script or, preferably, as part of my current script.

Relevant data:

This is the portion of the script that searches for files:

find $SOURCE_PATH > $TEMP_FIND_FILE

cat $TEMP_FIND_FILE |\
while read FN; do

The "do" is a bunch of meaningless junk that will make no sense unless you have a DVD library.

A typical SOURCE file looks like this:

/mnt/SERVER/DATADRIVE/DIRECTORY:/BACKUP/DATE/SERVER:

A typical "find" output looks like this:

/SERVER/DATADRIVE/DIRECTORY/filename.doc

I'd liek the output to look like this:

"/SERVER/DATADRIVE/DIRECTORY/filename.doc"

Any help would be greatly appreciated.

-welby
 
Old 01-14-2004, 11:09 AM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Quoting the filenames may not work in all cases. An easy way would be to change your script a bit and set the Internal Field Seperator (IFS) varaible to just include a newline. By default IFS is a newline and whitespace characters like tab and space.

Here is something that should work. Note that there can be no space after the IFS='

Code:
#!/bin/sh

SOURCE_PATH="/mnt"

IFS='
'

for FN in `find $SOURCE_PATH`; do
   # meaningless junk here

done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: add date to output line blizunt7 Programming 7 11-10-2004 04:45 AM
end of line character hyperriven Linux - General 1 04-07-2004 09:24 PM
how to avoid new line character gschrade Linux - Newbie 24 02-27-2004 12:14 PM
How do I add character+number to get char in C++? needforspeed Programming 10 02-10-2004 01:16 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM


All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration