Operating System - HP-UX
1828362 Members
3423 Online
109976 Solutions
New Discussion

Deleting last line in the file

 
SOLVED
Go to solution
mvr
Regular Advisor

Deleting last line in the file

Hello,

I need to delete the last line from the file (see attachment). The last line will always be same, but the numbers in between will grow. As you can conclude, the file is created from the user id in /etc/passwd
6 REPLIES 6
Jean-Luc Oudart
Honored Contributor
Solution

Re: Deleting last line in the file

There are different solution , why not "vi" ?
vi +$ dd
ZZ
EOP

Et Voila
Jean-Luc
fiat lux
James Specht
Trusted Contributor

Re: Deleting last line in the file

Quick fix.

head -`expr $(cat junk|wc -l) - 1` junk

Where junk = filename.
"Everyone can be taught to sculpt: Michelangelo would have had to be taught how not to. So it is with the great programmers."
Rodney Hills
Honored Contributor

Re: Deleting last line in the file

How about-

sed -e '$d' outputfile

HTH

-- Rod Hills
There be dragons...
mvr
Regular Advisor

Re: Deleting last line in the file

Thank you all.
I did it on the next way:

sed '/10010/d' uid > uid.new
mv uid.new uid

Thank you for ideas.

Miro
benoit Bruckert
Honored Contributor

Re: Deleting last line in the file

Hi,
this little script should works :
LINES=`wc -l | awk '{print $1}' `
LINES2=`expr $LINES - 1 `
head -n $LINES2 >

hth
Benoit
Une application mal pansée aboutit à une usine à gaze (GHG)
Steve Post
Trusted Contributor

Re: Deleting last line in the file

How get print lines 23 through 45 in file ABC.
cat ABC | sed -n '23,45p'

Remove the last line
cat ABC | sed '$d'

That's such a nice trick. I found this on the hp forums....somewhere. It's good to keep these little tricks around.

steve