The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh Checking if variable has 5 digits developncode UNIX for Dummies Questions & Answers 3 04-08-2008 03:57 PM
Digits display Spoorthi16 UNIX for Dummies Questions & Answers 3 10-01-2007 08:26 PM
Grep a line with between 3 and 5 digits ceemh3 UNIX for Dummies Questions & Answers 1 09-17-2007 03:24 PM
Only Digits as input namishtiwari UNIX for Dummies Questions & Answers 2 08-21-2007 06:23 AM
restrain the number of digits of a PID mlefebvr UNIX for Advanced & Expert Users 1 05-27-2002 09:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-28-2006
psarava psarava is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 3
How to cut last 10 digits off

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
  #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 08:17 AM.. Reason: Added awk based solution
  #3 (permalink)  
Old 08-28-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Other way:
Code:
hl=${#line}   
ll=$(( hl - 10 ))
echo ${line}|cut -c-${ll}-${hl}
  #4 (permalink)  
Old 08-28-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
One otherway:
Code:
echo $line | awk '{print substr($0, length($0)-9)}'
  #5 (permalink)  
Old 08-29-2006
psarava psarava is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 3
Thanks guys. They all work. You guys are really good.
Sponsored Links
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0