The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using SED to get n chars after given value from file Kally UNIX for Dummies Questions & Answers 12 12-19-2007 01:54 AM
How to convert C source from 8bit chars to 16bit chars? siegfried Shell Programming and Scripting 0 09-26-2007 11:26 AM
Retreive string between two chars danland Shell Programming and Scripting 25 06-25-2007 12:02 PM
replace chars, Jairaj Shell Programming and Scripting 7 02-28-2007 02:34 AM
Awk- catching the last two chars Gerry405 UNIX for Dummies Questions & Answers 9 11-22-2005 02:23 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007
Registered User
 

Join Date: Jul 2006
Posts: 139
cut last 4 chars

hi

i wanted to cut last 4 chars from a text file

Input

A-B-C-V-15-0115
A-BL-CLE-T-VALUE-0125
M-T-L-G-0115
AT-PR-PE-CCT-0135

Output

0115
0125
0115
0135

I tried cut -f - -d "-" (thinking cut -f 5- -d"-" gives 5 ot end of line so only - should give last but floped)
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-28-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,494
Code:
awk -F'-'  '{ print $NF} ' filename
Reply With Quote
  #3 (permalink)  
Old 06-28-2007
Registered User
 

Join Date: Jul 2006
Posts: 139
Quote:
Originally Posted by jim mcnamara View Post
Code:
awk -F'-'  '{ print $NF} ' filename

thanks Jim... Thats was Simple...
Reply With Quote
  #4 (permalink)  
Old 06-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,475
I could see a pattern there

so here's another one !

Code:
sed 's/^.*-//g' filename
Reply With Quote
  #5 (permalink)  
Old 06-28-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
sed 's/.*\(....\)$/\1/' input_file
Reply With Quote
  #6 (permalink)  
Old 06-28-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
while read str
do
	echo ${str##*-}
done < file
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0