remove hard returns at the end of each line in a paragraph? 
Author Message
 remove hard returns at the end of each line in a paragraph?

Hi,

I have text files in which each line within a paragraph is ended with
a hard return, and paragraphs are separated by blank lines. I want to
remove the hard returns at the end of the lines, so that a paragraph
would appear as a long line. How may I do this with gawk in Windows?

I searched the internet for answers, only came up with the following
code for sed. Unfortunately, I know nothing about sed, and am pretty
new to gawk as well. I'd appreciate if anyone can help. Thanks in
advance! -- HJW

     # sed script to change all paragraphs to long lines
     /./{H; $!d;}             # Put each paragraph into hold space
     x;                       # Swap hold space and pattern space
     s/^\(\n\)\(..*\)$/\2\1/; # Move leading \n to end of PatSpace
     s/\n\(.\)/ \1/g;         # Replace all other \n with 1 space
     # Uncomment the following line to remove excess blank lines:
     # /./!d;
     #---end of sed script---



Sun, 16 Oct 2005 10:18:32 GMT  
 remove hard returns at the end of each line in a paragraph?

Quote:

>Hi,

>I have text files in which each line within a paragraph is ended with
>a hard return, and paragraphs are separated by blank lines. I want to
>remove the hard returns at the end of the lines, so that a paragraph
>would appear as a long line. How may I do this with gawk in Windows?

gawk 'NF==0 {print;print;next}{printf{"%s ", $0}' infile

if you don't want the blank line, eliminate one print

Chuck Demas

--
  Eat Healthy        |   _ _   | Nothing would be done at all,

  Die Anyway         |    v    | That no one could find fault with it.



Sun, 16 Oct 2005 10:35:17 GMT  
 remove hard returns at the end of each line in a paragraph?

Quote:



> >Hi,

> >I have text files in which each line within a paragraph is ended with
> >a hard return, and paragraphs are separated by blank lines. I want to
> >remove the hard returns at the end of the lines, so that a paragraph
> >would appear as a long line. How may I do this with gawk in Windows?

> gawk 'NF==0 {print;print;next}{printf{"%s ", $0}' infile

> if you don't want the blank line, eliminate one print

> Chuck Demas

Thanks! It works great except for the extra { aftr printf. But that's
easy to spot and fix.

Thanks again,
HJW



Sun, 16 Oct 2005 16:37:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Removing End of Line and carrige return

2. Line Break / Feed (Hard Return)

3. Question: How to remove END OF LINE using AWK or SED

4. Ending sections/paragraphs

5. remove blank lines before lines beginning with string

6. blank lines/lines with spaces (how to remove)

7. New Line or new Paragraph

8. remove begin and end tags and its content in between

9. removing spaces from front and end of filenames

10. Removing carrige return in a specific position

11. removing the return stack

12. Removing a Record from a Returned SQL Recordset

 

 
Powered by phpBB® Forum Software