Seems I'm inundating this forum with questions, but anyway:
I am writing a script that should accept one and only one argument when called.
That argument should designate a file, either with path/filename or just filename.
Now to the difficult bit:
I want to figure out a way to store just the path in one variable and just the file name in another. I need this for subsequent manipulation.
I thought I should be able to do this with sed or awk, but I couldn't figure it out.
Also, I am fundamentally unsure whether it's a good idea to just look for the last "/" in the argument.
So I'm going to ask the one question I am starting to get famous for: is there a better way to achieve what I want?
The below code is what I currently have, giving you the context this is for, not tremendously important, but just so you can see where I'm going:
btw, I found it's actually better to use:
as this will take into account the possibility of only having a relative path (and not an absolute one) -- as in cut-it somedirectory/filetobecut
Or is there a reason why you had the two forward slashes?
Also, I still need to account for the possibility of the path being just "/" -- and of course the possibility of there not being a path at all, but at least what you've showed me is a solid start. Many thanks for that!
Man, that felt a little bit like what must have felt to find out about wget
Seriously, now. Perderabo: you rock.
And that's not to forget or diminish your input, druuna -- thanks to both!
This is what I made out of this:
and as you can see:
it absolutely cuts the mustard.
PS:
That't probably the "worst" thing about UNIX: It's too powerful and too diverse. No matter whether you know little or lots -- you're bound to run across a situation where you write a fantastic piece of code to handle a certain task -- only to find out later that, well, someone else had that problem before and s/he coded a solution which may or may not even be part of your default distribution. But one can only learn along the way.
Hi,
So I struggled to find a solution to the following problem:
I want to make sed print only part of multiple different paths.
So lets say we have
/path/path1/path2/logs/bla/blabla
/path/path1/path2/path3/logs/yadda/yadda/yadda
Can someone suggest a way to make sed or other... (5 Replies)
I have a small script to send copies of files to another computer used for tests but in the same location:pwd=`pwd`
for i in "$@"
do
echo "rcp -p $i comp-2:$pwd/$i"
rcp -p $i comp-2:$pwd/$i
echo "Finished with $i"
doneIs there a way I can check the parameter to see if it is a full... (5 Replies)
Hello Friends,
I need you help !
I have a scripts names runsteps.sh which contains command to run bunch of commands for each application you want to install " Oracle " Jboss" etc
echo " Which app you want to install Jboss" ? Yes or no?
read ans
depending on Yes or not it goes inside... (3 Replies)
Hi,
In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles".
This is my code :
... (1 Reply)
Hi,
In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles".
This is my code :
... (0 Replies)
Let say I have /home/user1/bin/ and i want it to be /root/bin
I tried : s/\/home\/user1/user2/
but it can't find the pattern user1.
I tried: s/*\/home\/user1*/user2/
as well same result
many thanks (4 Replies)
Hi
I have two path as follows
system/console/bin/code/sample/testfile.txt
system/console/bin/database/files/new/dbfile.txt
I need the output as
code/sample in first case
database/files/new in second case
That is I am omitting system/console/bin and the filename(s) in both... (2 Replies)
Hi all,
I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name.
Something like:
/dir1/dir2/dir2
and I want to select the last /dir2 where dir2 can be any kind of string.
Thanks a lot for your help.... (7 Replies)
Hi
I am trying to use sed to retrieve part of my html file's path. I am having a hard time getting what I want. Could someone give me some help?
I want to retrieve the section after html and before the file name
For example if I have the following, ... (3 Replies)
hi,
I am using solaris10. I have to write a bourne shell script, which copies files for the said destination path which is passed as an argument to the script.
it looks like this
myscript.sh /var/test -->destination path
now i would like to know what is the maximum length i can... (3 Replies)