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:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old February 23rd, 2005, 05:33 AM
sunvsunv sunvsunv is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 139 sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 16 h 10 m 55 sec
Reputation Power: 7
cut the fields from last

Can any one let me know how to cut the fields from last.

For example, If I have the data in the file named "data" and the column delimiter is "-".

content of data file :
===============
1-abcd-testthis-10
2-sdsd-secndlin-11
3-ffgf-thirdlin-12
4-jiku-fourthli-13

cut -d '-' -f 1
Then I get the first column. (1,2,3,4)

But now I want to get the first column from the end. (10,11,12,13)

Thansk for your time.

Reply With Quote
  #2  
Old February 23rd, 2005, 08:47 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by sunvsunv
Can any one let me know how to cut the fields from last.

For example, If I have the data in the file named "data" and the column delimiter is "-".

content of data file :
===============
1-abcd-testthis-10
2-sdsd-secndlin-11
3-ffgf-thirdlin-12
4-jiku-fourthli-13

cut -d '-' -f 1
Then I get the first column. (1,2,3,4)

But now I want to get the first column from the end. (10,11,12,13)

Thansk for your time.


No problem:
:
while read LINE; do
echo "$LINE" | awk -F'-' '{print $NF}'
done <<!
1-abcd-testthis-10
2-sdsd-secndlin-11
3-ffgf-thirdlin-12
4-jiku-fourthli-13
!

Try it.

Reply With Quote
  #3  
Old February 23rd, 2005, 12:05 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,078 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 14 h 28 m 26 sec
Reputation Power: 9
a) read man pages
b) did you try: cut -d '-' -f 4
c) forget awk && perl for such kind of jobs, cut and sed are your (ONE liner) friends
__________________
working on Solaris[5-9], preferred languages french and C.

Reply With Quote
  #4  
Old February 23rd, 2005, 12:22 PM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 36 m 43 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
sed -e 's/.*-\(.*\)$/\1/' file

Reply With Quote
  #5  
Old April 12th, 2005, 07:49 AM
sunvsunv sunvsunv is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 139 sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level)sunvsunv User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 16 h 10 m 55 sec
Reputation Power: 7
cutting the fields from the end.

Quote:
Originally Posted by guggach
b) did you try: cut -d '-' -f 4


My requirement is to get the first column from the end not the "4th" column. For simplicity, I had taken a row with 4 columns. In fact I am interested to cut the fields from the end.

Thanks.

Reply With Quote
  #6  
Old April 12th, 2005, 12:59 PM
dslc1000 dslc1000 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Ireland
Posts: 73 dslc1000 User rank is Private First Class (20 - 50 Reputation Level)dslc1000 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 14 h 11 m 52 sec
Reputation Power: 5
What zlutovsky suggested works for me:

Code:
cat file | awk -F'-' '{print $(NF)}'

Last edited by dslc1000 : April 12th, 2005 at 05:25 PM. Reason: Sorry ... I hadn't read the thread properly. zlutovsky had already provided the answer

Reply With Quote
  #7  
Old April 16th, 2005, 03:44 PM
vgersh99 vgersh99 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 47 vgersh99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 5 h 36 m 43 sec
Reputation Power: 4
Send a message via AIM to vgersh99 Send a message via MSN to vgersh99 Send a message via Yahoo to vgersh99
Quote:
Originally Posted by dslc1000
What zlutovsky suggested works for me:

Code:
cat file | awk -F'-' '{print $(NF)}'


UUOC

awk -F- '{print $NF}' file

Reply With Quote
  #8  
Old April 17th, 2005, 11:21 AM
dslc1000 dslc1000 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Ireland
Posts: 73 dslc1000 User rank is Private First Class (20 - 50 Reputation Level)dslc1000 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 14 h 11 m 52 sec
Reputation Power: 5
Yes, 'useless use of cat' indeed. My bad; thanks for pointing that out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > cut the fields from last


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 4 hosted by Hostway