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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To remove new line character shihabvk UNIX for Advanced & Expert Users 7 06-18-2009 08:44 AM
Remove last character of a term Raynon Shell Programming and Scripting 6 03-20-2008 06:04 AM
How to remove extraneous character vsmurali UNIX for Dummies Questions & Answers 7 03-18-2008 12:57 PM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 02:15 PM
Trying to remove single character from a line Iz3k34l UNIX for Dummies Questions & Answers 5 07-07-2007 02:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-19-2003
danhodges99
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Remove Last Character of Line

Hi,

I need to put the single line contents of a file into a variable, but remove the last character, for example the file would have this sort of contents:

2;4;3;10;67;54;96;

And I want the variable to be:

2;4;3;10;67;54;96 (notice the last ";" has gone).

Unfortunately I can't just do a cut of characters 1-x as the string will fluctuate in length!

Thanks.
  #2 (permalink)  
Old 05-19-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
If you're using ksh, you can strip off the last character like this:
x=${x%?}
  #3 (permalink)  
Old 05-19-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
This is a continuation of this post.

You can use this if you use ksh:

someVar=`awk '{ printf $2 ";" }' file`; someVar=${someVar%;}

-----
Oops, oh well same idea
  #4 (permalink)  
Old 05-21-2003
Bashar Bashar is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 66
with vi its possible

:%s/.$//g

this will delete every last char on each line.
  #5 (permalink)  
Old 05-21-2003
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
or how about sed. x=`echo $i|sed s/.$//`
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 03:41 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