Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
Using sed to convert a string to a character?
I need a command that will take a text file, and
convert carriage return, linefeed into a space,
but convert 2 consecutive carriage return linefeeds
into 1 or a single linefeed or cr.
Does anyone know sed well enough to do that for me?
i could only get sed to change one character into another,
but not change 4 characters into 2 or 1.
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Original Poster
Rep:
I tried tr first. I can only get it to change one
character into another, but i couldn't get it to
change a string to a character. I was trying
stuff like the below. tr man page only says stuff
about changing single characters into single
characters.
tr '\015\012' '\012' < $1 > $1.tmp.$$
what i did yesterday for lack of a better way, was to
use tr to change the newlines and carriage returns
to Capital Z's. Then i opened a text editor and
search and replaced each instance of ZZZZ with
a ~, then search and replaced each ZZ with a space.
then i used tr and converted each ~ to a new line.
Every couple of years i end up trying to do something
like this, and can't find a good way, short of writing
a little c program, which i do so rarely, i have to
relearn every time.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.