![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search pattern present in second field | imas | Shell Programming and Scripting | 6 | 08-20-2009 06:46 AM |
| Awk help needed for display particluar field alone for searching pattern | senthilkumar_ak | UNIX for Dummies Questions & Answers | 3 | 05-09-2009 06:18 AM |
| Print line if first Field matches a pattern | Raynon | Shell Programming and Scripting | 2 | 01-08-2009 06:07 AM |
| how do i pattern match a field with awk? | someone123 | Shell Programming and Scripting | 4 | 06-03-2008 08:08 AM |
| find pattern and replace another field | sergiioo | Shell Programming and Scripting | 3 | 04-11-2007 12:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How to get the last field of a string(pattern)?
b= find =/home/root/dir1/*.xml | xargs grep '</XML>' | cut -d ":" -f1 | uniq
From a folder that has many files, I am trying to get the filename which has </XML> in it using the above command. But while giving the result, the variable b is showing the path also. Ex: b=/homt/root/dir1/gg.xml. How can I just get the value gg.xml in b? The path I am giving as a variable.It is not hardcoded as (/home/root/dir1/*.xml) Ex: $path/*.xml.So the occurrence of "/" can vary. I am using KSH. Thanks, Floyd Last edited by asmfloyd; 1 Week Ago at 07:11 PM.. |
|
||||
|
Hi Scott,
It does not print anything for me.It just come out of the shell. My filenames are like file1.xml,file2.xml,... Also I tried echo ${b##*/}. That also does nothing.Bad luck.. Last edited by asmfloyd; 1 Week Ago at 01:47 AM.. Reason: Addition |
|
||||
|
You said that the path you wanted to search was in a variable. Did you change $MY_PATH to something meaningful for you?
I did test this before I posted it! Code:
$ cat file1.xml
<XML>
this is some xml
</XML>
$ cat file2.xml
<XML>
this is some more xml
</XML>
$ MY_PATH=.
$ b=$(find $MY_PATH -exec grep -l '</XML>' {} \; | xargs -I{} basename {} | uniq -u>
# echo $b
file1.xml file2.xml
|
|
||||
|
Thanks friends
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|