12-19-2007
Extracting a substring starting from last occurance of a string/character
Hi All,
This is Ram. I'm new to this forum & new to shell scripts as well. I've a requirement in which I want to extract a substring from a given string based on last occurance of a character.
for eg.
I have a string of a file name with absolute path like
$filename=/aaa/bbb/ccc/ddd/xyz.txt
I want to extract only the actual file name ie, xyz.txt
The no. of directories ie, / will be dynamic. So I want to find the last occurance of / in the given string & to extract the string after the last /
can I have some ideas / suggestions please.
Thanks ,
Ram.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Ok, I'm stumped and can't seem to find relevant info.
(I'm not even sure, I might have asked something similar before.):
I'm trying to use shell scripting/UNIX commands to extract URLs from a fairly large web page, with a view to ultimately wrapping this in PHP with exec() and including the... (2 Replies)
Discussion started by: ropers
2 Replies
2. Shell Programming and Scripting
hi all,
i need an urgent help for writing a shell script which will extract out and print a substring which is the shortest substring from the given string where first and last character of that substring will be given by the user.
for e.g.
if str="abcdpqracdpqaserd"
now if the user gives 'a'... (18 Replies)
Discussion started by: pankajd
18 Replies
3. Shell Programming and Scripting
Suppose I have a text file that contains the tags <foo> and <bar>. The text file can have unlimted occurances of <foo> and <bar> and looks somthing like this:
<foo>
Some
Text
<foo>
Some
Text
<bar>
Some
Text
<foo>
Some (1 Reply)
Discussion started by: ArterialTool
1 Replies
4. Shell Programming and Scripting
How to extract the last character of a string in bash?
---------- Post updated at 03:56 PM ---------- Previous update was at 03:55 PM ----------
Suppose "abcde" is a string. i want to extract the last character i.e. "e". (1 Reply)
Discussion started by: proactiveaditya
1 Replies
5. Shell Programming and Scripting
Hi awk and sed gurus,
Please help me in the following.
I have the following entries in the file
ABCDErules
AbHDPrules
ABCrules
--
--
and other entries in the file.
Now, I want to extract from the file that contain entries for *rules and process it separately.
How can i do it... (6 Replies)
Discussion started by: sdosanjh
6 Replies
6. Shell Programming and Scripting
Hi,
I would like to extract a substring from a string in unix.
eg:
./checkfile.sh -- i need only checkfile.sh from this string.
Could someone help me out in this...
Regards
Arun (19 Replies)
Discussion started by: arunkumarmc
19 Replies
7. Shell Programming and Scripting
Hi All,
Was wondering how I can do the following....
I have a String as follows
"ACCTRL000005022RRWDKKEEDKDD...."
This string can be in a file called tail.out or in a Variable called $VAR2
Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies
8. Shell Programming and Scripting
Hi,
I have string in variable like '/u/dolfin/in/DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010'
and i want to conevrt this string into only "DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010" (i.e file name).
Is there any command to extracting string in some part ?(rather than whole path)?
... (5 Replies)
Discussion started by: shyamu544
5 Replies
9. Shell Programming and Scripting
Hi,
I am new to Unix. I am trying to extract a substring from an input string: Ex -
input string: deploy_v11_9_1
i want to extract and store the value v11_9_1 from the input string in a new variable.
I am using following command in my shell script file:
echo "Enter the folder name u... (5 Replies)
Discussion started by: Pranav Bhasker
5 Replies
10. Shell Programming and Scripting
Hello.
First best wishes for everybody.
here is the input file ("$INPUT1") contents :
BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_debug%%=() { local -a L_ARRAY;
BASH_FUNC_message_end_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies