The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to delete first 5 lines and last five lines in all text files ragavendran31 Shell Programming and Scripting 10 02-21-2008 07:58 AM
delete some lines fongthai Shell Programming and Scripting 2 10-16-2007 11:54 PM
How to delete more lines kamathg Shell Programming and Scripting 1 10-05-2007 07:39 AM
delete blank lines or lines with spaces only vascobrito UNIX for Dummies Questions & Answers 3 01-13-2004 07:36 AM
delete lines.. alisevA3 UNIX Desktop for Dummies Questions & Answers 8 05-29-2002 09:33 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-30-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
sed help - delete last 2 lines.

I have been reading through the sed one liners, trying to understand what is happening.

Code:
# delete the last 2 lines of a file
sed 'N;$!P;$!D;$d'
The above will delete the last 2 line of a file. I tried analyzing what happens. And I got lost

This is what I understood so far from the above.

N; Read the complete file into the pattern-space.
$!P; Print upto last but one line.
$!D; Delete upto the last-but one line
$d Delete the last line in the pattern-space.

What is wrong in my analysis ? Please explain what the sed script does ?

Thanks,
Vino

Last edited by vino; 05-31-2005 at 07:18 AM..
  #2 (permalink)  
Old 06-08-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Can anyone help me on this ?

Thanks,
Vino
  #3 (permalink)  
Old 06-08-2005
r2007's Avatar
r2007 r2007 is offline
Registered User
  
 

Join Date: Jun 2005
Location: China
Posts: 73
N; Read the next line into the pattern-space.
$!P; Print the first line of the pattern-space, if the current line is not the last line.
$!D; Delete the first line of the pattern-space, if the current line is not the last line.
$d Delete everything in the pattern-space, if the current line is the last line.
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 05:22 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