Not able to find the perfect code...Geting confused in between


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to find the perfect code...Geting confused in between
# 1  
Old 02-18-2013
Oracle Not able to find the perfect code...Geting confused in between

I have to find last delimiter in each line of a file and store the value after the last '/' in a variable in ksh script...Pls Pls help meSmilieThe file is as shown below:
Code:
/opt/apps/cobqa/apps/abadv/bind/advc0007.bnd
/opt/apps/cobqa/apps/abbrio/bind/naac6115.bnd
/opt/apps/cobqa/apps/abbrio/bind/trkc4822.bnd
/opt/apps/cobqa/apps/abbrio/bind/trkc4823.bnd
/opt/apps/cobqa/apps/abcmp/bind/cmpc0105.bnd



I know how to find the last '/' but don't know how to repetitively find it and store it in variable.

Last edited by Scrutinizer; 02-18-2013 at 02:42 AM.. Reason: code tags
# 2  
Old 02-18-2013
Use a while read loop and cut the line using parameter expansion: ${line##*/}
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 02-18-2013
Code:
awk -F/ '{print $NF}' infile
advc0007.bnd
naac6115.bnd
trkc4822.bnd
trkc4823.bnd
cmpc0105.bnd

This User Gave Thanks to Jotne For This Post:
# 4  
Old 02-18-2013
Code:
while read line
do
    x=$(echo "$line" | sed 's:.*/::')
    # work with $x
    echo $x
done < file

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-18-2013
Hey guys thanks a lot...I will try out and let you know how it worked...:-)

---------- Post updated at 01:09 PM ---------- Previous update was at 12:16 PM ----------

Is it possible for me to add a new line with some text after each line in this record???
# 6  
Old 02-21-2013
Yes, with every iteration you can print your processed line bit and the some extra line..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find + Symlinks = me confused

So i have read the man pages a few time. Searched google but I am not quite sure i understand all the lingo. What i want to do is list all files on / except i dont want any symlinks (because if I am searching / I will find the "true" file...correct?) So there is the -P, -H, and '-type l'... (2 Replies)
Discussion started by: nitrobass24
2 Replies

2. UNIX for Dummies Questions & Answers

Can you perfect my sed ?

I want to print only the lines that meet the criteria : "worde:" and "wordo;" I got this far: sed -n '/\(*\)\1e:\1o;/p;' But it doesn't quite work. Can someone please perfect it and tell me exactly how its a fixed version/what was wrong with mine? Thanks heaps, (1 Reply)
Discussion started by: maximus73
1 Replies

3. UNIX for Advanced & Expert Users

Kernel Modules Not geting built

I installed in VM the Mandriva Linux with 2.6.27 kernel. But presently when I fire make the modules .ko does not get built. I get the following output on firing command in the kernel module folder. $ make Building first_driver.c ... make: Entering directory... (1 Reply)
Discussion started by: rupeshkp728
1 Replies

4. AIX

Geting a value dynamically from topas

Hi all, I got an idea to get a value (like Syscall or %comp details for example)dynamically from topas. Is there any way to do this. I guss there must be some door opened for this. I tried running topas and redirecting to a file but in vain. The idea is, script should run topas in... (4 Replies)
Discussion started by: jayadeava
4 Replies

5. Shell Programming and Scripting

Confused with find

Hi ,I am reading and trying examples with find ,but I am little bit confused, How can I search only in sertain directory,Could you give me some example Thanks a lot find . -size +10k find . -name "name" (4 Replies)
Discussion started by: lio123
4 Replies

6. Shell Programming and Scripting

geting a value out of awk script

the value of flag is reset inside the awk statments and is not getting echoed out of it. how can this be done?? #!/bin/ksh flag=0 awk -F '' '$2 == "ABCD" && $6 == "MNOP"{flag=1}' file.xml echo $flag I am always getting the value of flag as "0" , even after the $2 is "ABCD" and $6 is... (2 Replies)
Discussion started by: skyineyes
2 Replies

7. Shell Programming and Scripting

geting user input from php and using perl for execution

I am using festival speech synthesis system and I would like to allow user input in a browser. This will be taken by a php page which is then supposed to pass the input text to a perl script. The perl script should pass this text to the festival engine by executing a unix command. this in turn... (2 Replies)
Discussion started by: wairimus
2 Replies

8. Shell Programming and Scripting

geting the real path

Hi there, Is there any way to obtain a real path from a weird path. For example : /foo/../bar/ -> /bar/ /foo/. -> /foo/ Thanks in advance Santiago (5 Replies)
Discussion started by: chebarbudo
5 Replies

9. Solaris

I am geting error while trying to stop managed server of WEB LOGIC

Dear All, I am geting error while trying to stop managed server of WEB LOGIC through the command stop_wls managed1_wlsdom02.Can anyone tell me why I am geting this error?managed1_wlsdom02.pid exists at the path mentioned. Do you need any other details?... (0 Replies)
Discussion started by: ASHISH MISHRA
0 Replies

10. Shell Programming and Scripting

geting server name(ipaddress)

hi, can any one say how to get the server name if we know the ipaddress ie nslookup gives ipaddress if server name is given in the same way can i have server name if i know ipaddress thanks & regards babu :o (1 Reply)
Discussion started by: babu@shell
1 Replies
Login or Register to Ask a Question