Removing last character from each line of file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Removing last character from each line of file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-18-2005
cjhancock cjhancock is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 1 July 2010, 5:36 AM EDT
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Removing last character from each line of file

How can I remove the last character from each line of a file?

This must be done without "funny" characters, as I want to transfer the code to/from Windows.

Any ideas?
Sponsored Links
    #2  
Old 02-18-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 November 2014, 4:34 AM EST
Location: Foxborough, MA
Posts: 7,670
Thanks: 153
Thanked 586 Times in 551 Posts
sed -e 's/\(.*\).$/\1/g' file

As it's been outlined in the thread, transfer/ftp your files in ASCII mode.
Sponsored Links
    #3  
Old 02-18-2005
cjhancock cjhancock is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 1 July 2010, 5:36 AM EDT
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Not so simple

Trouble is, I'm transferring a zip file containing binary and ascii files - I FTP the zip file as binary, then use unzip - so I'm in the lap of the gods...

Thanks
    #4  
Old 02-18-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 November 2014, 4:34 AM EST
Location: Foxborough, MA
Posts: 7,670
Thanks: 153
Thanked 586 Times in 551 Posts
do you have TWO files to transfer or ONE zip?

if you have 2, transfer zip in binary and others in ascii.

AM I misisng the point here?
Sponsored Links
    #5  
Old 02-18-2005
cjhancock cjhancock is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 1 July 2010, 5:36 AM EDT
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Missing the point

I've got ONE zip file containing both binary and ASCII files. I transfer it as binary, then unzip it. If I try to unzip using the -a switch, one of the binary files gets interpreted as ASCII which is a bigger problem.

Any clearer? I really appreciate your help
Sponsored Links
    #6  
Old 02-18-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 28 November 2014, 4:34 AM EST
Location: Foxborough, MA
Posts: 7,670
Thanks: 153
Thanked 586 Times in 551 Posts
and if you use '-b' or '-B'?
I'm not a real guru when it comes to 'unzip' - just reading 'man unzip'.
Sponsored Links
    #7  
Old 02-18-2005
cjhancock cjhancock is offline
Registered User
 
Join Date: Feb 2005
Last Activity: 1 July 2010, 5:36 AM EDT
Posts: 16
Thanks: 1
Thanked 0 Times in 0 Posts
Fixed

Me neither. I suspect that's what it's doing now - transferring everything as binary.

Anyway, your sed script seems to do the trick, so I'm happy.

Thanks again for your help - it's cool when someone half way round the world solves a problem for me!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing first and last character of line baskivs Shell Programming and Scripting 5 10-17-2011 11:56 AM
Need help removing last character of every line if certain character raptor25 UNIX for Dummies Questions & Answers 5 07-21-2011 05:25 PM
How to concat line first and then removing the ^M character vsantoshusa Shell Programming and Scripting 11 10-03-2008 06:50 PM
removing a character and addending to end in each line in a file arunkumar_mca UNIX for Dummies Questions & Answers 5 01-30-2008 12:48 AM
removing new line character ammu Shell Programming and Scripting 2 01-15-2008 10:12 AM



All times are GMT -4. The time now is 05:34 AM.