UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 11th, 2006, 06:37 AM
gkrishnag gkrishnag is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 2 gkrishnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 2 sec
Reputation Power: 0
Geeting only required Data

I have a file:
gk@dev1:~> cat more.txt
iam :here home/usr/bin
iam :here home/usr
iam :here help/home/bin
iam :here home/bin/var

i want to cut the some of the letters from the above file and print only the last letters like
my data would be
bin
usr
bin
var

How do i do that?

any one ..need help?

Reply With Quote
  #2  
Old September 11th, 2006, 11:59 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
The easiest way is probably to replace all of the / with white space then print the last column.

Code:
sed -e 's/\// /g' test.txt | awk '{print $NF}'

Reply With Quote
  #3  
Old September 12th, 2006, 03:48 AM
Verletto Verletto is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: Sweden
Posts: 14 Verletto User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 56 m 46 sec
Reputation Power: 0
No need to change the delimiter, just specify it:

Code:
awk '{FS="/";print $NF}' file 

Reply With Quote
  #4  
Old September 12th, 2006, 05:15 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Quote:
Originally Posted by Verletto
No need to change the delimiter, just specify it:

Code:
awk '{FS="/";print $NF}' file 


I decided against that, because the file does not necessarily have to contain a /.

i.e.

Code:
iam :here home/usr/bin
iam :here help/home/bin
iam :here home

Reply With Quote
  #5  
Old September 12th, 2006, 09:56 AM
ghostdog74 ghostdog74 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 100 ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level)ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level)ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 20 h 48 m 7 sec
Reputation Power: 3
Quote:
Originally Posted by gkrishnag
I have a file:
gk@dev1:~> cat more.txt
iam :here home/usr/bin
iam :here home/usr
iam :here help/home/bin
iam :here home/bin/var

i want to cut the some of the letters from the above file and print only the last letters like
my data would be
bin
usr
bin
var

How do i do that?

any one ..need help?


Parsing of strings/text is very easy, in Python.
Code:
>>> for lines in open("more.txt"):
... 	os.path.split(lines.split()[-1])[-1]
... 
'bin'
'bin'
'home'

Reply With Quote
  #6  
Old September 12th, 2006, 10:46 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 767 SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level)SimonJM User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 23 h 25 m 34 sec
Reputation Power: 336
Very interesting, but not the output I woudl have expected - should it not have returned:

Code:
bin
usr
bin
var

from that input file?

Reply With Quote
  #7  
Old September 12th, 2006, 06:51 PM
ghostdog74 ghostdog74 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 100 ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level)ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level)ghostdog74 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Day 20 h 48 m 7 sec
Reputation Power: 3
Quote:
Originally Posted by SimonJM
Very interesting, but not the output I woudl have expected - should it not have returned:

Code:
bin
usr
bin
var

from that input file?


I had a different input file for testing, and pasted the wrong output.

Code:
>>> for lines in open("more.txt"):
... 	print os.path.split(lines.split()[-1])[-1]
... 
bin
usr
bin
var

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Geeting only required Data


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT