The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-28-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
Quote:
Originally Posted by psarava
Hi I'm new to this. I need to cut off the last 10 digits from a line.
I've used awk {'print $4'} filename.txt | cut -c 32-42 but this does not guarantee only the last 10 characters.

Please help. Thanks.

Sara

If you are using BASH as shell. This would work.


Code:
while read line; do echo ${line:(-10)}; done < filename

Another way using awk(gawk)


Code:
awk '{LEN=length($0);print substr($0,LEN-9)}' filename


Last edited by vish_indian; 08-28-2006 at 09:17 AM.. Reason: Added awk based solution