Sponsored Content
Top Forums Shell Programming and Scripting sed random \n for "n" range of character occurrences Post 302977609 by p1ne on Wednesday 20th of July 2016 12:07:30 PM
Old 07-20-2016
sed random \n for "n" range of character occurrences

I'd like to put paragraph breaks \n\n randomly between 5 - 10 occurrences of the dot character (.), for an entire text file. How to do that?

In other words, anywhere between every 5 -10 sentences, a new paragraph will generate. There are no other uses of the (.) except for sentence breaks in the file.

Thanks in advance for help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

2. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

3. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

4. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

5. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

6. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

7. Shell Programming and Scripting

sed escape character for comment string "/*"

Good afternoon all, I'm hoping my newbie question can help bolster someone's street_cred.sh today. I'm trying to "fingerprint" SQL on its way into the rdbms for a benchmarking process (so I can tie the resource allocation back to the process more precisely). To do this, I'm essentially... (4 Replies)
Discussion started by: toeharp
4 Replies

8. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

9. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

10. Shell Programming and Scripting

Replacing character "|" in given character range

Hi I am having file : 1|2443094 |FUNG SIU TO |CLEMENT 2|2443095 |FUNG KIL FO |REMENT This file contains only 3 fields delimeted by "|". Last field is a decsription filed and it contains character "|". Due to this my output if breaking in 4 fields. I... (7 Replies)
Discussion started by: krsnadasa
7 Replies
Reflow(3pm)						User Contributed Perl Documentation					       Reflow(3pm)

NAME
Text::Reflow - Perl module for reflowing text files using Knuth's paragraphing algorithm. SYNOPSIS
use Text::Reflow qw(reflow_file reflow_string reflow_array); reflow_file($infile, $outfile, key => value, ...); $output = reflow_string($input, key => value, ...); $output = reflow_array(@input, key => value, ...); DESCRIPTION
These routines will reflow the paragraphs in the given file, filehandle, string or array using Knuth's paragraphing algorithm (as used in TeX) to pick "good" places to break the lines. Each routine takes ascii text data with paragraphs separated by blank lines and reflows the paragraphs. If two or more lines in a row are "indented" then they are assumed to be a quoted poem and are passed through unchanged (but see below) The reflow algorithm tries to keep the lines the same length but also tries to break at punctuation, and avoid breaking within a proper name or after certain connectives ("a", "the", etc.). The result is a file with a more "ragged" right margin than is produced by "fmt" or "Text::Wrap" but it is easier to read since fewer phrases are broken across line breaks. For "reflow_file", if $infile is the empty string, then the input is taken from STDIN and if $outfile is the empty string, the output is written to STDOUT. Otherwise, $infile and $outfile may be a string, a FileHandle reference or a FileHandle glob. A typical invocation is: reflow_file("myfile", ""); which reflows the whole of myfile and prints the result to STDOUT. KEYWORD OPTIONS The behaviour of Reflow can be adjusted by setting various keyword options. These can be set globally by referencing the appropriate variable in the Text::Reflow package, for example: $Text::Reflow::maximum = 80; $Text::Reflow::optimum = 75; will set the maximum line length to 80 characters and the optimum line length to 75 characters for all subsequent reflow operations. Or they can be passed to a reflow_ function as a keyword parameter, for example: $out = reflow_string($in, maximum => 80, optimum => 75); in which case the new options only apply to this call. The following options are currently implemented, with their default values: optimum => [65] The optimum line length in characters. This can be either a number or a reference to an array of numbers: in the latter case, each optimal line length is tried in turn for each paragraph, and the one which leads to the best overall paragraph is chosen. This results in less ragged paragraphs, but some paragraphs will be wider or narrower overall than others. maximum => 75 The maximum allowed line length. indent => "" Each line of output has this string prepended. "indent => string" is equivalent to "indent1 => string, indent2 => string". indent1 => "" A string which is used to indent the first line in any paragraph. indent2 => "" A string which is used to indent the second and subsequent line in any paragraph. quote => "" Characters to strip from the beginning of a line before processing. To reflow a quoted email message and then restore the quotes you might want to use quote => "> ", indent => "> " skipto => "" Skip to the first line starting with the given pattern before starting to reflow. This is useful for skipping Project Gutenberg headers or contents tables. skipindented => 2 If "skipindented" = 0 then all indented lines are flowed in with the surrounding paragraph. If "skipindented" = 1 then any indented line will not be reflowed. If "skipindented" = 2 then any two or more adjacent indented lines will not be reflowed. The purpose of the default value is to allow poetry to pass through unchanged, but not to allow a paragraph indentation from preventing the first line of the paragraph from being reflowed. noreflow => "" A pattern to indicate that certain lines should not be reflowed. For example, a table of contents might have a line of dots. The option: noreflow => '(.s*){4}.' will not reflow any lines containing five or more consecutive dots. frenchspacing => 'n' Normally two spaces are put at the end of a sentance or a clause. The "frenchspacing" option (taken from the TeX macro of the same name) disables this feature. oneparagraph => 'n' Set this to 'y' if you want the whole input to be flowed into a single paragraph, ignoring blank lines in the input. semantic => 30 This parameter indicates the extent to which semantic factors matter (breaking on punctuation, avoiding a break within a clause etc.). Set this to zero to minimise the raggedness of the right margin, at the expense of readability. namebreak => 10 Penalty for splitting up a name sentence => 20 Penalty for sentence widows and orphans (ie splitting a line immediately after the first word in a sentence, or before the last word in a sentence) independent => 10 Penalty for independent clause widows and orphans. dependent => 6 Penalty for dependent clause widows and orphans. shortlast => 5 Penalty for a short last line in a paragraph (one or two words). connpenalty => 1 Multiplier for the "negative penalty" for breaking at a connective. In other words, increasing this value makes connectives an even more attractive place to break a line. EXPORT None by default. AUTHOR
Original "reflow" perl script written by Michael Larsen, larsen@edu.upenn.math. Modified, enhanced and converted to a perl module with XSUB by Martin Ward, martin@gkc.org.uk SEE ALSO
perl(1). See "TeX the Program" by Donald Knuth for a description of the algorithm used. perl v5.14.2 2011-11-15 Reflow(3pm)
All times are GMT -4. The time now is 06:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy