LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 01-09-2003, 09:25 PM   #1
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Rep: Reputation: 52
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.
 
Old 01-10-2003, 03:34 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
how about using tr instead?

tr 'list-of-characters-to-change' 'character-to-change-to'
 
Old 01-10-2003, 06:13 AM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix, 98,2000 + various
Posts: 3,171

Original Poster
Rep: Reputation: 52
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.

Last edited by whansard; 01-10-2003 at 06:55 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove last character from file/string linuxchump Programming 34 06-08-2009 05:01 AM
Picking a character from a string randomly swatward Programming 2 08-14-2005 02:21 AM
insert string with sed greg108 Programming 7 02-18-2005 02:11 PM
how to print the first character in a string using strtok its_godzilla Programming 5 02-02-2005 11:22 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM


All times are GMT -5. The time now is 06:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration