problem with path extract from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with path extract from file
# 1  
Old 06-28-2010
problem with path extract from file

hello,

i have a configuration file app.conf under /tmp, containing values like :
param1=/data/something
param2=/data/somethingelse

i have a bash script that has to list the files under the path that corresponds to param2 :

#!/bin/bash

dir=$(cat tmp/app.conf | grep param2 | sed "s/param2//")
echo "path needed"
echo $dir
Until here, everything is fine, i get /data/somethingelse shown on the console.


ls $dir -> gives me this error :
: No such file or directory

Could anyone help me with this one ?

Thanks a lot,
Chaa
# 2  
Old 06-28-2010
Try
Code:
ls "$dir"

# 3  
Old 06-28-2010
the "sed" pattern should be:

Code:
sed "s/param2=//"

hence, the second line should look like:

Code:
dir=$(cat tmp/app.conf | grep param2 | sed "s/param2=//")

otherwise the dir variable has the "=" at the beginning.

Last edited by Franklin52; 06-28-2010 at 05:39 PM.. Reason: Please use code tags
# 4  
Old 06-28-2010
thank you both for your answers
actually
this is what i wrote in the bash :
Code:
dir=$(cat tmp/app.conf | grep param2 | sed "s/param2=//")

and
Code:
ls "$dir"

isn't working either...

Last edited by Franklin52; 06-28-2010 at 05:40 PM.. Reason: Please use code tags
# 5  
Old 06-28-2010
Maybe there just isn't such directory on your system Smilie Try using "ls" on command line with that directory:
Code:
ls /data/somethingelse

# 6  
Old 06-28-2010
Quote:
Originally Posted by chaa
thank you both for your answers
actually
this is what i wrote in the bash : dir=$(cat tmp/app.conf | grep param2 | sed "s/param2=//")

and
ls "$dir"
isn't working either...
can you post the output of ls command?
# 7  
Old 06-28-2010
What isn't working? What is the content of $dir ? Any messages?

I think you need to supply an absolute path ( /tmp/ instead of tmp/ )
Also, the selecting statement can be further optimized:
Code:
dir=$(sed -n "s/param2=//p" /tmp/app.conf)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem to match a path in a file and put it into a variable

Hello,:p I made a script which do a backup on remote servers with a rsync command. I have a config.cfg with the IPs and the paths where it will copy the directory. The problem is that it doesn't match the paths, So, here my script and its output with the debug : #!/bin/bash # PATHS... (7 Replies)
Discussion started by: Arnaudh78
7 Replies

2. Shell Programming and Scripting

How to extract strings from full path when full path is not fixed

/Path/snowbird9/nrfCompMgrRave1230100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird6/nrfCompMgrRave1220100920.log.gz:09/20/2010 06:14:51 ERROR Error Message. /Path/snowbird14/nrfCompMgrRave920100920.log.gz:09/20/2010 06:14:51 ERROR Error Message.... (0 Replies)
Discussion started by: Shirisha
0 Replies

3. Shell Programming and Scripting

one liner to extract path from PATH variable

Hi, Could anyone help me in writing a single line code by either using (sed, awk, perl or whatever) to extract a specific path from the PATH environment variable? for eg: suppose the PATH is being set as follows PATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/bin/java:/usr/bin/perl3.4 ... (2 Replies)
Discussion started by: royalibrahim
2 Replies

4. Shell Programming and Scripting

Extract RPM name from path to .rpm file

It's the end of the day and I just can't get my head around this. I'm trying to extract just the name of the RPM from the path to a .rpm file. So from: /home/me/rpm/RPMS/i386/nagios-our-plugins-1.2-6.i386.rpmI need to extract 'nagios-our-plugins'. I can't get the awk syntax right: awk '{... (5 Replies)
Discussion started by: aussieos
5 Replies

5. Shell Programming and Scripting

Extract directory from a file path

Im trying to extract a directory from a path entered by the user Lets say the path is path=/home/bliss/files/myfile.txt i wanna extract "/home/bliss/files" from $path ... how can i do this? (4 Replies)
Discussion started by: mrudula009
4 Replies

6. Shell Programming and Scripting

Extract The File Path using SED

hi, I have a file path like usr/scripts/pass/bin and usr/scripts/pass/line I want to extract first three characters using sed Like for path usr/scripts/pass/bin i want to extract usr/scripts/pass and for path usr/scripts/pass/line i want to extract usr/scripts/pass (10 Replies)
Discussion started by: Diggi
10 Replies

7. UNIX for Dummies Questions & Answers

Problem writing file path to txt file

if test -z "$1" then echo "you must give a filename or filepath" else path=`dirname $1` f_name =`basename $1` if path="." then path=`pwd` fi fi cat $f_name $path >> index.txt The only problem I am encountering with this is writing $path to index.txt Keeps going gaga: cat:... (1 Reply)
Discussion started by: Vintage_hegoog
1 Replies

8. Shell Programming and Scripting

Problem with File path

How to pass a file path to open a file? I am using cygwin. I want to open a file from a particular path, say C:\Test\File1,. This file path is stored in a variable. I am able to cat a file like this : cat "c:\Test\File1" but i want the same thing to happen in my script file through a variable... (3 Replies)
Discussion started by: sandeep_hi
3 Replies

9. UNIX for Dummies Questions & Answers

cc path problem - no acceptable path found

Hello everyone, I'm a unix noob. I have a powerbook running mac os x 10.4 and for one of my classes I need to install the latest version of php (5.0.5). I'm following the instructions at http://developer.apple.com/internet/opensource/php.html to install but I've run into a problem. The... (2 Replies)
Discussion started by: kendokendokendo
2 Replies

10. UNIX for Dummies Questions & Answers

extract only file name from full path file name

What is the smartest way to just extract file name from a full path name. e.g. if I have /usr/sanjay/bin/file_name.c I want only file_name.c Sanjay (2 Replies)
Discussion started by: sanjay92
2 Replies
Login or Register to Ask a Question