Remove last character from line

Multi tool use
Clash Royale CLAN TAG#URR8PPP
I want to remove last character from a line:
[root@ozzesh ~]#df -h | awk ' print $5 '
Use%
22%
1%
1%
59%
51%
63%
5%
Expected result:
Use
22
1
1
59
51
63
5
text-processing
add a comment |
I want to remove last character from a line:
[root@ozzesh ~]#df -h | awk ' print $5 '
Use%
22%
1%
1%
59%
51%
63%
5%
Expected result:
Use
22
1
1
59
51
63
5
text-processing
2
Is it always a%
sign?
– Bernhard
Jul 15 '13 at 5:55
add a comment |
I want to remove last character from a line:
[root@ozzesh ~]#df -h | awk ' print $5 '
Use%
22%
1%
1%
59%
51%
63%
5%
Expected result:
Use
22
1
1
59
51
63
5
text-processing
I want to remove last character from a line:
[root@ozzesh ~]#df -h | awk ' print $5 '
Use%
22%
1%
1%
59%
51%
63%
5%
Expected result:
Use
22
1
1
59
51
63
5
text-processing
text-processing
edited Sep 18 '13 at 12:20
Braiam
23.1k1976137
23.1k1976137
asked Jul 15 '13 at 5:46
Özzesh
1,18361625
1,18361625
2
Is it always a%
sign?
– Bernhard
Jul 15 '13 at 5:55
add a comment |
2
Is it always a%
sign?
– Bernhard
Jul 15 '13 at 5:55
2
2
Is it always a
%
sign?– Bernhard
Jul 15 '13 at 5:55
Is it always a
%
sign?– Bernhard
Jul 15 '13 at 5:55
add a comment |
9 Answers
9
active
oldest
votes
sed 's/.$//'
To remove the last character.
But in this specific case, you could also do:
df -Ph | awk 'NR > 1 print $5+0'
With the arithmetic expression ($5+0
) we force awk
to interpret the 5th field as a number, and anything after the number will be ignored.
9
print +$5
will work as well...
– jasonwryan
Jul 15 '13 at 6:37
1
@jasonwryan, unfortunately, there are a lot ofawk
implementations where that doesn't work, where the+
unary operator is just ignored and doesn't force conversion of strings to numerical.
– Stéphane Chazelas
Sep 11 '15 at 8:49
add a comment |
With sed
, this is pretty easy:
$ cat file
Use%
22%
1%
1%
59%
51%
63%
5%
$ sed 's/.$//' file
Use
22
1
1
59
51
63
5
The syntax is s(ubstitute)/search/replacestring/
. The .
indicates any character, and the $
the end of the line. So .$
will remove the last character only.
In this case, your complete command would look:
df -h | awk ' print $5' | sed 's/.$//'
2
The pipe tosed
is redundant: it can be done inawk
:df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
add a comment |
I have two solutions :
cut:
echo "somestring1" | rev | cut -c 2- | rev
Here you reverse the string and cut the string from 2nd character and reverse again.
sed :
echo "somestring1" | sed 's/.$//'
Here you will search for regular expression
.$
which means any characters followed by a last character and replace it with null//
(between the two slashes)
add a comment |
In awk, you could do one of
awk 'sub(/%$/,"",$5); print $5'
awk 'print substr($5, 1, length($5)-1)'
add a comment |
another approach:
mapfile -t list < <(df -h)
printf '%sn' "$list[@]%?"
Turn it into a function:
remove_last()
local char=$1:-?; shift
mapfile -t list < <("$@")
printf '%sn' "$list[@]%$char"
Then call it like this:
remove_last '%' df -h
mapfile
is a bash4 feature.
The catch here is that you must supply a character to remove; if you want it to just be whatever the last character happens to be then you must pass '?'
or ''
. quotes required.
add a comment |
$ df -h | awk 'print $5' | cut -d '%' -f1
add a comment |
Try with this:
df -h | awk ' print $5 ' | sed "s/%//"
The normal use is:
(ie)
VALUE=987654321
echo X123456789X | sed "s/123456789/$VALUE/"
Response should be: X987654321X
add a comment |
df -h | awk 'NR > 1 print $5 ' | cut -d "%" -f1
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use ofcut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.
– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
add a comment |
sed -ie '$d' filename
here -i is to write changes
e means expression
$ means last line
d means delete
Note:Without -e option $ wont work
Optional: To delete 1st and last line use sed -ie '1d;$d'
filename
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f83038%2fremove-last-character-from-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
sed 's/.$//'
To remove the last character.
But in this specific case, you could also do:
df -Ph | awk 'NR > 1 print $5+0'
With the arithmetic expression ($5+0
) we force awk
to interpret the 5th field as a number, and anything after the number will be ignored.
9
print +$5
will work as well...
– jasonwryan
Jul 15 '13 at 6:37
1
@jasonwryan, unfortunately, there are a lot ofawk
implementations where that doesn't work, where the+
unary operator is just ignored and doesn't force conversion of strings to numerical.
– Stéphane Chazelas
Sep 11 '15 at 8:49
add a comment |
sed 's/.$//'
To remove the last character.
But in this specific case, you could also do:
df -Ph | awk 'NR > 1 print $5+0'
With the arithmetic expression ($5+0
) we force awk
to interpret the 5th field as a number, and anything after the number will be ignored.
9
print +$5
will work as well...
– jasonwryan
Jul 15 '13 at 6:37
1
@jasonwryan, unfortunately, there are a lot ofawk
implementations where that doesn't work, where the+
unary operator is just ignored and doesn't force conversion of strings to numerical.
– Stéphane Chazelas
Sep 11 '15 at 8:49
add a comment |
sed 's/.$//'
To remove the last character.
But in this specific case, you could also do:
df -Ph | awk 'NR > 1 print $5+0'
With the arithmetic expression ($5+0
) we force awk
to interpret the 5th field as a number, and anything after the number will be ignored.
sed 's/.$//'
To remove the last character.
But in this specific case, you could also do:
df -Ph | awk 'NR > 1 print $5+0'
With the arithmetic expression ($5+0
) we force awk
to interpret the 5th field as a number, and anything after the number will be ignored.
edited Dec 23 '18 at 12:50
answered Jul 15 '13 at 5:56


Stéphane Chazelas
300k54564913
300k54564913
9
print +$5
will work as well...
– jasonwryan
Jul 15 '13 at 6:37
1
@jasonwryan, unfortunately, there are a lot ofawk
implementations where that doesn't work, where the+
unary operator is just ignored and doesn't force conversion of strings to numerical.
– Stéphane Chazelas
Sep 11 '15 at 8:49
add a comment |
9
print +$5
will work as well...
– jasonwryan
Jul 15 '13 at 6:37
1
@jasonwryan, unfortunately, there are a lot ofawk
implementations where that doesn't work, where the+
unary operator is just ignored and doesn't force conversion of strings to numerical.
– Stéphane Chazelas
Sep 11 '15 at 8:49
9
9
print +$5
will work as well...– jasonwryan
Jul 15 '13 at 6:37
print +$5
will work as well...– jasonwryan
Jul 15 '13 at 6:37
1
1
@jasonwryan, unfortunately, there are a lot of
awk
implementations where that doesn't work, where the +
unary operator is just ignored and doesn't force conversion of strings to numerical.– Stéphane Chazelas
Sep 11 '15 at 8:49
@jasonwryan, unfortunately, there are a lot of
awk
implementations where that doesn't work, where the +
unary operator is just ignored and doesn't force conversion of strings to numerical.– Stéphane Chazelas
Sep 11 '15 at 8:49
add a comment |
With sed
, this is pretty easy:
$ cat file
Use%
22%
1%
1%
59%
51%
63%
5%
$ sed 's/.$//' file
Use
22
1
1
59
51
63
5
The syntax is s(ubstitute)/search/replacestring/
. The .
indicates any character, and the $
the end of the line. So .$
will remove the last character only.
In this case, your complete command would look:
df -h | awk ' print $5' | sed 's/.$//'
2
The pipe tosed
is redundant: it can be done inawk
:df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
add a comment |
With sed
, this is pretty easy:
$ cat file
Use%
22%
1%
1%
59%
51%
63%
5%
$ sed 's/.$//' file
Use
22
1
1
59
51
63
5
The syntax is s(ubstitute)/search/replacestring/
. The .
indicates any character, and the $
the end of the line. So .$
will remove the last character only.
In this case, your complete command would look:
df -h | awk ' print $5' | sed 's/.$//'
2
The pipe tosed
is redundant: it can be done inawk
:df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
add a comment |
With sed
, this is pretty easy:
$ cat file
Use%
22%
1%
1%
59%
51%
63%
5%
$ sed 's/.$//' file
Use
22
1
1
59
51
63
5
The syntax is s(ubstitute)/search/replacestring/
. The .
indicates any character, and the $
the end of the line. So .$
will remove the last character only.
In this case, your complete command would look:
df -h | awk ' print $5' | sed 's/.$//'
With sed
, this is pretty easy:
$ cat file
Use%
22%
1%
1%
59%
51%
63%
5%
$ sed 's/.$//' file
Use
22
1
1
59
51
63
5
The syntax is s(ubstitute)/search/replacestring/
. The .
indicates any character, and the $
the end of the line. So .$
will remove the last character only.
In this case, your complete command would look:
df -h | awk ' print $5' | sed 's/.$//'
answered Jul 15 '13 at 5:58
Bernhard
7,64533967
7,64533967
2
The pipe tosed
is redundant: it can be done inawk
:df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
add a comment |
2
The pipe tosed
is redundant: it can be done inawk
:df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
2
2
The pipe to
sed
is redundant: it can be done in awk
: df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
The pipe to
sed
is redundant: it can be done in awk
: df -h | awk 'gsub(/%/,""); print $5'
– jasonwryan
Jul 15 '13 at 6:33
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
@jasonwryan Then I like Stephane's solution better.
– Bernhard
Jul 15 '13 at 6:35
add a comment |
I have two solutions :
cut:
echo "somestring1" | rev | cut -c 2- | rev
Here you reverse the string and cut the string from 2nd character and reverse again.
sed :
echo "somestring1" | sed 's/.$//'
Here you will search for regular expression
.$
which means any characters followed by a last character and replace it with null//
(between the two slashes)
add a comment |
I have two solutions :
cut:
echo "somestring1" | rev | cut -c 2- | rev
Here you reverse the string and cut the string from 2nd character and reverse again.
sed :
echo "somestring1" | sed 's/.$//'
Here you will search for regular expression
.$
which means any characters followed by a last character and replace it with null//
(between the two slashes)
add a comment |
I have two solutions :
cut:
echo "somestring1" | rev | cut -c 2- | rev
Here you reverse the string and cut the string from 2nd character and reverse again.
sed :
echo "somestring1" | sed 's/.$//'
Here you will search for regular expression
.$
which means any characters followed by a last character and replace it with null//
(between the two slashes)
I have two solutions :
cut:
echo "somestring1" | rev | cut -c 2- | rev
Here you reverse the string and cut the string from 2nd character and reverse again.
sed :
echo "somestring1" | sed 's/.$//'
Here you will search for regular expression
.$
which means any characters followed by a last character and replace it with null//
(between the two slashes)
edited Aug 12 '15 at 8:01
Jakuje
16.2k52953
16.2k52953
answered Aug 12 '15 at 7:28
Guru
24124
24124
add a comment |
add a comment |
In awk, you could do one of
awk 'sub(/%$/,"",$5); print $5'
awk 'print substr($5, 1, length($5)-1)'
add a comment |
In awk, you could do one of
awk 'sub(/%$/,"",$5); print $5'
awk 'print substr($5, 1, length($5)-1)'
add a comment |
In awk, you could do one of
awk 'sub(/%$/,"",$5); print $5'
awk 'print substr($5, 1, length($5)-1)'
In awk, you could do one of
awk 'sub(/%$/,"",$5); print $5'
awk 'print substr($5, 1, length($5)-1)'
answered Jul 15 '13 at 10:37
glenn jackman
50.4k570107
50.4k570107
add a comment |
add a comment |
another approach:
mapfile -t list < <(df -h)
printf '%sn' "$list[@]%?"
Turn it into a function:
remove_last()
local char=$1:-?; shift
mapfile -t list < <("$@")
printf '%sn' "$list[@]%$char"
Then call it like this:
remove_last '%' df -h
mapfile
is a bash4 feature.
The catch here is that you must supply a character to remove; if you want it to just be whatever the last character happens to be then you must pass '?'
or ''
. quotes required.
add a comment |
another approach:
mapfile -t list < <(df -h)
printf '%sn' "$list[@]%?"
Turn it into a function:
remove_last()
local char=$1:-?; shift
mapfile -t list < <("$@")
printf '%sn' "$list[@]%$char"
Then call it like this:
remove_last '%' df -h
mapfile
is a bash4 feature.
The catch here is that you must supply a character to remove; if you want it to just be whatever the last character happens to be then you must pass '?'
or ''
. quotes required.
add a comment |
another approach:
mapfile -t list < <(df -h)
printf '%sn' "$list[@]%?"
Turn it into a function:
remove_last()
local char=$1:-?; shift
mapfile -t list < <("$@")
printf '%sn' "$list[@]%$char"
Then call it like this:
remove_last '%' df -h
mapfile
is a bash4 feature.
The catch here is that you must supply a character to remove; if you want it to just be whatever the last character happens to be then you must pass '?'
or ''
. quotes required.
another approach:
mapfile -t list < <(df -h)
printf '%sn' "$list[@]%?"
Turn it into a function:
remove_last()
local char=$1:-?; shift
mapfile -t list < <("$@")
printf '%sn' "$list[@]%$char"
Then call it like this:
remove_last '%' df -h
mapfile
is a bash4 feature.
The catch here is that you must supply a character to remove; if you want it to just be whatever the last character happens to be then you must pass '?'
or ''
. quotes required.
edited Jul 25 '13 at 7:38
answered Jul 25 '13 at 7:27
Josh McGee
57836
57836
add a comment |
add a comment |
$ df -h | awk 'print $5' | cut -d '%' -f1
add a comment |
$ df -h | awk 'print $5' | cut -d '%' -f1
add a comment |
$ df -h | awk 'print $5' | cut -d '%' -f1
$ df -h | awk 'print $5' | cut -d '%' -f1
edited Aug 17 '16 at 10:26


Rahul
8,99412842
8,99412842
answered Aug 17 '16 at 10:21
ashok
111
111
add a comment |
add a comment |
Try with this:
df -h | awk ' print $5 ' | sed "s/%//"
The normal use is:
(ie)
VALUE=987654321
echo X123456789X | sed "s/123456789/$VALUE/"
Response should be: X987654321X
add a comment |
Try with this:
df -h | awk ' print $5 ' | sed "s/%//"
The normal use is:
(ie)
VALUE=987654321
echo X123456789X | sed "s/123456789/$VALUE/"
Response should be: X987654321X
add a comment |
Try with this:
df -h | awk ' print $5 ' | sed "s/%//"
The normal use is:
(ie)
VALUE=987654321
echo X123456789X | sed "s/123456789/$VALUE/"
Response should be: X987654321X
Try with this:
df -h | awk ' print $5 ' | sed "s/%//"
The normal use is:
(ie)
VALUE=987654321
echo X123456789X | sed "s/123456789/$VALUE/"
Response should be: X987654321X
answered Mar 27 '17 at 4:37


Chuss
211
211
add a comment |
add a comment |
df -h | awk 'NR > 1 print $5 ' | cut -d "%" -f1
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use ofcut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.
– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
add a comment |
df -h | awk 'NR > 1 print $5 ' | cut -d "%" -f1
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use ofcut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.
– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
add a comment |
df -h | awk 'NR > 1 print $5 ' | cut -d "%" -f1
df -h | awk 'NR > 1 print $5 ' | cut -d "%" -f1
edited Apr 1 '17 at 20:12


phk
3,98652153
3,98652153
answered Apr 1 '17 at 19:48
user223910
111
111
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use ofcut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.
– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
add a comment |
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use ofcut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.
– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
This answer could be more helpful to others beyond OP if you could provide a bit of explanation regarding how it works and possibly why this might be better than the alternatives
– Fox
Apr 1 '17 at 20:09
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Welcome to Unix Stackexchange! You can take the tour to get a feel for how this site works. When giving an answer it is preferable to give some explanation as to WHY your answer is the one the reader wants. This means it is best if you give some explanation of how it works. If you look above, you will see that all of the highly voted answers explain the code.
– Stephen Rauch
Apr 1 '17 at 20:10
Upvoted for the use of
cut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.– Titou
Dec 10 '18 at 10:36
Upvoted for the use of
cut -d '%' -f1
which is the correct answer to get everything in the line up to the first '%'.– Titou
Dec 10 '18 at 10:36
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
Plus I believe only harmful / wrong answers should ever get downvoted below 0.
– Titou
Dec 10 '18 at 10:38
add a comment |
sed -ie '$d' filename
here -i is to write changes
e means expression
$ means last line
d means delete
Note:Without -e option $ wont work
Optional: To delete 1st and last line use sed -ie '1d;$d'
filename
add a comment |
sed -ie '$d' filename
here -i is to write changes
e means expression
$ means last line
d means delete
Note:Without -e option $ wont work
Optional: To delete 1st and last line use sed -ie '1d;$d'
filename
add a comment |
sed -ie '$d' filename
here -i is to write changes
e means expression
$ means last line
d means delete
Note:Without -e option $ wont work
Optional: To delete 1st and last line use sed -ie '1d;$d'
filename
sed -ie '$d' filename
here -i is to write changes
e means expression
$ means last line
d means delete
Note:Without -e option $ wont work
Optional: To delete 1st and last line use sed -ie '1d;$d'
filename
answered Oct 24 '18 at 18:44


sudhir tataraju
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f83038%2fremove-last-character-from-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Is it always a
%
sign?– Bernhard
Jul 15 '13 at 5:55