Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

script in sed

Original Message
Name: tspj88
Date: February 18, 2004 at 11:26:34 Pacific
Subject: script in sed
OS: Unix
CPU/Ram: 512
Comment:
I don't understand what the following script does:
sed -e '
:more
/^$/N
s/^\n//
tmore
'
Can anyone give me the explaination?
Joe

Report Offensive Message For Removal


Response Number 1
Name: Dlonra
Date: February 18, 2004 at 17:23:53 Pacific
Subject: script in sed
Reply: (edit)
i am not a sed mayven, so i read the man page (man sed) which includes
: label - Label for b and t commands
n N Read/append the next line of input into the pattern space
t label - conditional branch

I also made a test file to edit
So, /^$/N gets rid of blank lines
not sure of the rest

-e is not needed

let me know when you unravel the rest


Report Offensive Follow Up For Removal

Response Number 2
Name: tspj88
Date: February 18, 2004 at 18:27:02 Pacific
Subject: script in sed
Reply: (edit)
In my test, I had following findings:
/^$/N
search empty lines and N tells to search pattern that are split into 2 lines or immediately quit when reading the End-of-File.
s/^\n//
remove the newline characters
So, I got the same conclusion:
this can remove the empty lines from the input.


Report Offensive Follow Up For Removal

Response Number 3
Name: Jim Boothe
Date: February 20, 2004 at 14:50:59 Pacific
Subject: script in sed
Reply: (edit)
Yes, that code eliminates empty (null) lines. For each null line encountered, it pulls the next line into the pattern space (main work buffer), then deletes the null line at the front of the pattern space. Doing it that way requires for it to loop so that it can delete multiple null lines in succession. Without the loop, if it encountered several null lines in succession, it would delete only the first of each pair of null lines.

As tspj88 says, the s/^\n// is what actually eliminates the null line. That substitution command eliminates the newline character, which is all that a null line is composed of. But that newline character would not be available for elimination with a substitution command without pulling a second line into the buffer with the N command. You cannot eliminate the newline character at the end of the only (or last) line in the pattern space. If you have 5 lines in the pattern space, you can act upon the 4 newline characters that separate those lines.

A much simpler way to do the same thing would be:

sed '/^$/d'


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: script in sed

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs

Best WinMo phone of 2008


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC