Split text into paragraphs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split text into paragraphs
# 1  
Old 07-25-2012
Question Split text into paragraphs

Hi all!

I want to make a code to split sentences into paragraphs maybe
4-5 sentences into one <p>text</p>
there are no new lines in the text string

any ideas with AWK, SSH?

Thank you!
# 2  
Old 07-25-2012
sample input and desired output? i am not getting a condition for splitting the data!
# 3  
Old 07-25-2012
I want to split the text with 5 sentences in every paragraph

input
Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.Text text text text text text text text text text text text text.


output
<p>Text text text text text text text text text text text text text. Text text text text text text text text text text text text text. Text text text text text text text text text text text text text. Text text text text text text text text text text text text text.</p><p>Text text text text text text text text text text text text text . Text text text text text text text text text text text text text. Text text text text text text text text text text text text text. Text text text text text text text text text text text text text. Text text text text text text text text text text text text text. Text text text text text text text text text text text text text.</p>Text text text text text text text text text text text text text. Text text text text text text text text text text text text text.....

any ideas? Smilie

Thanks!
# 4  
Old 07-25-2012
This splits every sentence.
Code:
awk -v RS="." '!/^\n$/ { print "<p>" $0 ".</p>" }' < input > output

This splits every 5 sentences.

Code:
awk -v RS="." '!/^\n$/ { if(!((++N)%5)) printf("</p>\n<p>"); print; } END { print "</p>" }' < input > output

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 07-25-2012
Thank you !!! Smilie
# 6  
Old 07-25-2012
Code:
 oops wrong post--snipped

This User Gave Thanks to msabhi For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Center image between two text paragraphs.

I want to show a page with an image between 2 any paragraphs. I tried the following script. But the image is not centered. SUSE Paste <!DOCTYPE html> <html> <head> <style> center.center_1 { margin: auto; width: 60%; ... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Split the text file into two

OS : RHEL 7.3 I have a file like below. I want to move (cut and paste) the first 7 lines of file1 to another file (file2). How can I do this ? In my real life scenario, I will be moving first 12 millions lines of file1 to file2 $ cat file1.txt 7369|SMITH |CLERK | ... (5 Replies)
Discussion started by: kraljic
5 Replies

3. Shell Programming and Scripting

Split a text file into multiple text files?

I have a text file with entries like 1186 5556 90844 7873 7722 12 7890.6 78.52 6679 3455 9867 1127 5642 ..N so many records like this. I want to split this file into multiple files like cluster1.txt, cluster2.txt, cluster3.txt, ..... clusterN.txt. (4 Replies)
Discussion started by: sammy777
4 Replies

4. Shell Programming and Scripting

splitting a large text file into paragraphs

Hello all, newbie here. I've searched the forum and found many "how to split a text file" topics but none that are what I'm looking for. I have a large text file (~15 MB) in size. It contains a variable number of "paragraphs" (for lack of a better word) that are each of variable length. A... (3 Replies)
Discussion started by: lupin..the..3rd
3 Replies

5. Shell Programming and Scripting

Split text file

Hi all, I am very new to shell scripting and some help is greatly appreciated. I have 10 column based text files, i would like to split each of them into 6 files ; the 1st one having columns 1, 2 ,3,4 , the second one having columns 1,2,8,9 etc. Is there a way I could get 60 files out my... (3 Replies)
Discussion started by: shreymuk
3 Replies

6. Shell Programming and Scripting

Script to split text files

Hi All, I'm fairly new to scripting, so need a little help to get started with this problem. I don't mind whether I go for an awk/bash/other approach, I don't really know which would be best suited to the problem... Lets say I have a 10000 line text file, I would like to split this up into a... (6 Replies)
Discussion started by: phil8258
6 Replies

7. Shell Programming and Scripting

Perl Split for text in file

Hi all I have written Perl script to swap the strings in the second a third column from a text file. My input file format is : the|empty|the|det lake|empty|lake|conj_and was|empty|was|auxpass drained|empty|drained|conj_and birds|empty|bird|s|nn The expected output file format is... (11 Replies)
Discussion started by: my_Perl
11 Replies

8. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

9. Shell Programming and Scripting

Split text in all chars

Hello, I need a shell script to split a text to all chars. The text is: Hello World But i need it: H e l l o W o r l d (7 Replies)
Discussion started by: WSyS
7 Replies

10. UNIX for Dummies Questions & Answers

Split text file by pages

Hello! Firts of all, I'm sorry for my English. My problem: I have text file with few Form Feed symbols (FF, ASCII code =12) inside (for example - some report, consists of some pages for printing). I want to split this text by pages - each page (until FF symbol) in single file. I... (2 Replies)
Discussion started by: ranri
2 Replies
Login or Register to Ask a Question