The UNIX and Linux Forums  


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



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 !!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-07-2009
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; 11-07-2009 at 07:11 PM..
  #2 (permalink)  
Old 11-07-2009
scottn scottn is online now Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,610
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 11-08-2009
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; 11-08-2009 at 01:47 AM.. Reason: Addition
  #4 (permalink)  
Old 11-08-2009
fpmurphy's Avatar
Moderator
 

Join Date: Dec 2003
Location: Florida
Posts: 2,030
One way ..

Code:
$ b=/homt/root/dir1/gg.xml
$ echo $b
/homt/root/dir1/gg.xml
$ echo $(basename $b)
gg.xml

  #5 (permalink)  
Old 11-08-2009
scottn scottn is online now Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,610
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 11-08-2009
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 Off


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 07:46 AM
Awk help needed for display particular field alone for searching pattern senthilkumar_ak UNIX for Dummies Questions & Answers 3 05-09-2009 07: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 09:08 AM
find pattern and replace another field sergiioo Shell Programming and Scripting 3 04-11-2007 01:19 AM



All times are GMT -4. The time now is 10:55 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