Read file with paths in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file with paths in it
# 1  
Old 02-02-2010
Read file with paths in it

Hi,

I have a file as followed :
Code:
 100.100.100.100
 \\server\volume\path\file.pdf

My script :

Code:
  counter=1
  while read -r myline
   do
     if [ $counter -eq 1]
      then
         FTPHOST=$myline
     fi
     if [ $counter -eq 2]
      then
         SERVERPATH=$myline
     fi
     counter=$((counter+1))
    done < /path/to/inputfile


I want to read each line and put it into variables. My problem is that the path isn't displayed as it should be. (There is one backslash gone !)

the result :

Code:
   FTPHOST = 100.100.100.100
   SERVERPATH = \server\volume\path\file.pdf


Can someone help me out

Thanks

Last edited by pludi; 02-02-2010 at 05:50 AM.. Reason: code tags, removed links
# 2  
Old 02-02-2010
Bug

hi frank ,

Could get clear info on your requirement .

Its advisable that you attach a sample file.

what i have understood from your description is you have a file like this :

ipadreees path

ipadress path

and you want to isolate and put ip_addr and paths to variables.

Is this correct ?
# 3  
Old 02-02-2010
Hello, for me, it's working with bash

I've copied your script and added echo $FTPHOST echo $SERVERPATH.
It returns :

100.100.100.100
\\server\volume\path\file.pdf

I just put a space at the end of the lines
Code:
if [ $counter -eq 2 ]  <--  space between "2" and "]"


Last edited by xanthos; 02-02-2010 at 06:43 AM.. Reason: Add code tag
# 4  
Old 02-02-2010
@ultimatix
Quote:
what i have understood from your description is you have a file like this :

ipadreees path

ipadress path

and you want to isolate and put ip_addr and paths to variables.

Is this correct ?
It's a file with 2 lines, one with the ip_adr, the other line with the path.
(file in attach)

@xanthos

Did the path display okay ? The space at the end of the lines was there in my script but not in the post so my guess is that it isn't okay.
# 5  
Old 02-02-2010
Quote:
Originally Posted by FrankToy

@xanthos

Did the path display okay ? The space at the end of the lines was there in my script but not in the post so my guess is that it isn't okay.

Yes I,ve got the two backslash at the beginning,
You can try with #!/bin/bash
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. Shell Programming and Scripting

Storing multiple file paths in a variable

I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Discussion started by: cranfordio
3 Replies

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

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

5. Shell Programming and Scripting

Rewriting file paths in XML file within bash script

Hi guys, I'm working on a large set of scripts to move files around several servers and manipulate them for our staff. Basically we're shooting things, the videos hit a server and then need organised due to the language they've been shot in. Our XML (designed for Apple's Final Cut Pro) is right... (6 Replies)
Discussion started by: omfgbunnies
6 Replies

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

7. Shell Programming and Scripting

How to read a list of paths from a file?

Hi everyone! I'm pretty bad at shell scripting and I am trying to create a java launcher. The idea is to store in a configuration file different paths (each for a different java version) and then, run a .sh file that would read the specified java path and execute the .jar file. This is what i have... (7 Replies)
Discussion started by: mostacholoco
7 Replies

8. Shell Programming and Scripting

tar after replacing paths from a file

There is a file paths.txt with paths containing data for example E:/<BUILD_NAME>/data/common E:/<BUILD_NAME>/log/common E:/<BUILD_NAME>/temp/common E:/<BUILD_NAME>/code/common While reading this file I want to replace the <BUILD_NAME> from a variable $BUILD in the following command: tar... (1 Reply)
Discussion started by: muaz
1 Replies

9. Shell Programming and Scripting

tar the paths from a input file

Hi, I have a file paths.txt with all the file paths. I want to tar everything in those paths to a file. for example paths.txt contains /data/extention /logs/extension /code/extenstion Now I want to tar using command tar cvf extention.tar path1 path2 where path1 -> /data/extention... (2 Replies)
Discussion started by: muaz
2 Replies

10. UNIX for Dummies Questions & Answers

How to set the File Paths for Inputs and Outputs

I have couple of shell scripts. Each shell script accepts command line argument as inputfilename. Each shell script creates a summary file, status file. All these files are stored in a particular directory...Eg InputFile is to be picked from /home/ProjectName/ftp_inputfiles/ Outputs are to... (1 Reply)
Discussion started by: Amruta Pitkar
1 Replies
Login or Register to Ask a Question