The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
asmfloyd asmfloyd is offline
Registered User
  
 

Join Date: May 2009
Posts: 7
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..
  #2 (permalink)  
Old 1 Week Ago
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,033
One options:

Code:
b=$(find $MY_PATH -exec grep -l '</XML>' {} \; | xargs -I{} basename {} | uniq -u)
puts all the filenames which match into b.

Not so great if any file names have spaces in them.
  #3 (permalink)  
Old 1 Week Ago
asmfloyd asmfloyd is offline
Registered User
  
 

Join Date: May 2009
Posts: 7
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
  #4 (permalink)  
Old 1 Week Ago
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,910
One way ..
Code:
$ b=/homt/root/dir1/gg.xml
$ echo $b
/homt/root/dir1/gg.xml
$ echo $(basename $b)
gg.xml
  #5 (permalink)  
Old 1 Week Ago
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,033
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
  #6 (permalink)  
Old 1 Week Ago
asmfloyd asmfloyd is offline
Registered User
  
 

Join Date: May 2009
Posts: 7
Thanks friends
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0