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

Sed newline

Original Message
Name: chain
Date: October 2, 2003 at 04:05:56 Pacific
Subject: Sed newline
OS: sunOS5.9
CPU/Ram: not sure
Comment:
Hi,
I am writting a script that replaces a certain character in a string with a newline using sed command. I tried this :
cat t.txt | sed 's/href/\n/g' > test.txt

but it doesnt work. Anyone can help me out here?


Report Offensive Message For Removal


Response Number 1
Name: Anagram
Date: October 6, 2003 at 14:55:19 Pacific
Subject: Sed newline
Reply: (edit)
This depends on the sed you are using, and in what context. I believe GNU's sed can do what you tried. More traditional sed (say OSF1) cannot, yet can quote an actual newline character. This means that at the prompt, you type the command right up to where you are going to insert a newline, then use the backslash to begin an escape, then press enter (sounds wierd but it works!) now you should have a "secondary prompt" and you complete the command line and press enter. This will look something like this at your terminal:

[bash] cat t.txt | sed 's/href/\
> /g' > test.txt

Note that the greater-than symbol on the second line is not typed in, that is the default secondary prompt string, which shows up when the shell has determined that your pressing of the enter key meant that you needed an embedded (not terminating) End-of-line.
The rules are the same for a shell script, but be very careful that your editor does not append *any* bytes to the end of the line (particularly a space character gets stuck on sometimes). Here is what the code would look like in a script:

#!/bin/bash
cat t.txt | sed 's/href/\
/g' > test.txt

Strange at first but remember that End-of-line is just a byte, no different from any other character, its just our interactive software that treats it differently in certain circumstances.
If you wanted the same script to replace a pattern with 3 newlines, then you could do this:

#!/bin/bash
cat t.txt | sed 's/href/\
\
\
/g' > test.txt



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: Sed newline

Comments:

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


Data Recovery Software




DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12

help mandriva install last straw!

Icon Scaling in Explorer Bar


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