|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
Quote:
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. ![]() |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
sed -e 's/.*-\(.*\)$/\1/' file
|
|
#5
|
|||
|
|||
|
cutting the fields from the end.
Quote:
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. |
|
#6
|
|||
|
|||
|
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 |
|
#8
|
|||
|
|||
|
Yes, 'useless use of cat' indeed. My bad; thanks for pointing that out.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > cut the fields from last |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|