Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete the last character of a file

Status
Not open for further replies.

Roti78

Programmer
Nov 3, 2003
2
HU
Hello everybody!

How can I delete the last character of a multilined file?

Thanx

Roti
 
Try something like this:
Code:
sed -e 's!.$!!' /path/to/input >/path/to/output

Hope This Help
PH.
 
Thanx,

but what if I have some new lines at the end of the file, and I want to delete that new line character?
 
Or :
sed -e '$s/.$//' file_in > file_out

The number of fullstops(periods) denote the number of characters to be deleted.

Dickie Bird (:)-)))
 
To remove 'empty' lines :
sed '/^$/d' filename > newfilename
To remove line(s) with just a space :
sed '/^ /d' filename > newfilename


Dickie Bird (:)-)))
 
To remove all newlines from a file,

awk '{printf $0}' file1 > file2
 
I am not sure if you meant to delete the last character of every line or the last character of the file. This should delete newline characters from the end of each line:
02:35:17 | cat dog
filename=$1
awk '{printf("%s ",$0)};END{print}' $filename
02:35:24 | cat testfile
alpha
beta
gamma
delta
02:35:35 | dog testfile
alpha beta gamma delta
02:35:43 |

r063r7
 
I came across this method of concatenating strings while
studing for a test. It accomplishes the same thing as some
of the previous posts.

20:08:07 | cat testfile
alpha
beta
gamma
delta

20:08:17 | nawk '{list=list" "$1}END{print list}' testfile
alpha beta gamma delta

r063r7
 
Here's some perl blasphemy to remove that last character or newline.

perl -pe 'chop if eof'

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top