Sponsored Content
Top Forums Shell Programming and Scripting sed random \n for "n" range of character occurrences Post 302977644 by p1ne on Wednesday 20th of July 2016 09:59:12 PM
Old 07-20-2016
I don't really know what I'm doing with that sed command; it's just showing my thought process as to what I want to achieve.

Input example is a blob of text with periods (.) marking sentences. The following output example would have random \n\n breaks, between every random 3 - 6 periods (for example):
Code:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam nibh. Nunc  varius facilisis eros. Sed erat. 

In in velit quis arcu ornare laoreet.  Curabitur adipiscing luctus massa. Integer ut purus ac augue commodo  commodo. Nunc nec mi eu justo tempor consectetuer. Etiam vitae nisl. In  dignissim lacus ut ante. 

Cras elit lectus, bibendum a, adipiscing vitae,  commodo et, dui. Ut tincidunt tortor. Donec nonummy, enim in lacinia  pulvinar, velit tellus scelerisque augue, ac posuere libero urna eget  neque. 

Cras ipsum. Vestibulum pretium, lectus nec venenatis volutpat,  purus lectus ultrices risus, a condimentum risus mi et quam.  Pellentesque auctor fringilla neque. Duis eu massa ut lorem iaculis  vestibulum. Maecenas facilisis elit sed justo.

Moderator's Comments:
Mod Comment Please use CODE tags for all sample input, sample output, and code segments (as required by forum rules).

Last edited by Don Cragun; 07-21-2016 at 12:12 AM.. Reason: Add CODE tags.
 

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
Text::Wrap(3pm) 					User Contributed Perl Documentation					   Text::Wrap(3pm)

NAME
GD::Text::Wrap - Wrap strings in boxes SYNOPSIS
use GD; use GD::Text::Wrap; my $gd = GD::Image->new(800,600); # allocate colours, do other things. my $text = <<EOSTR; Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. EOSTR my $wrapbox = GDTextWrap->new( $gd, line_space => 4, color => $black, text => $text, ); $wrapbox->set_font(gdMediumBoldFont); $wrapbox->set_font('arial', 12); $wrapbox->set(align => 'left', width => 120); $wrapbox->draw(10,140); $gd->rectangle($wrap_box->get_bounds(10,140), $color); DESCRIPTION
GD::Text::Wrap provides an object that draws a formatted paragraph of text in a box on a GD::Image canvas, using either a builtin GD font or a TrueType font. METHODS
This class doesn't inherit from GD::Text directly, but delegates most of its work to it (in fact to a GD::Text::Align object. That means that most of the GD::Text::Align methods are available for this class, specifically "set_font" and "font_path". Other methods and methods with a different interface are described here: GD::Text::Wrap->new( $gd_object, attribute => value, ... ) Create a new object. The first argument to new has to be a valid GD::Image object. The other arguments will be passed to the set() method for initialisation of the attributes. $wrapbox->set( attribute => value, ... ) set the value for an attribute. Valid attributes are: width The width of the box to draw the text in. If unspecified, they will default to the width of the GD::Image object. line_space The number of pixels between lines. Defaults to 2. para_space, paragraph_space The number of extra pixels between paragraphs, above line_space. Defaults to 0. color, colour Synonyms. The colour to use when drawing the font. Will be initialised to the last colour in the GD object's palette. align, alignment Synonyms. One of 'justified' (the default), 'left', 'right' or 'center'. text The text to draw. This is the only attribute that you absolutely have to set. preserve_nl If set to a true value, newlines in the text will cause a line break. Note that lines will still be justified. If only one word appears on the line, it could get ugly. Defaults to 0. As with the methods, attributes unknown to this class get delegated to the GD::Text::Align class. $wrapbox->get( attribute ); Get the current value of an attribute. All attributes mentioned under the "set()" method can be retrieved $wrapbox->get_bounds() Returns the bounding box of the box that will be drawn with the current attribute settings as a list. The values returned are the coordinates of the upper left and lower right corner. ($left, $top, $right, $bottom) = $wrapbox->get_bounds(); Returns an empty list on error. NOTE: The return list of this method may change in a future implementation that allows angled boxes. $wrapbox->draw(x, y) Draw the box, with (x,y) as the top right corner. Returns the same values as the "getbounds()" method. NOTE: The return list of this method may change in a future implementation that allows angled boxes. NOTES
As with all Modules for Perl: Please stick to using the interface. If you try to fiddle too much with knowledge of the internals of this module, you may get burned. I may change them at any time. You can only use TrueType fonts with version of GD > 1.20, and then only if compiled with support for this. If you attempt to do it anyway, you will get errors. Even though this module lives in the GD::Text namespace, it is not a GD::Text. It does however delegate a lot of its functionality to a contained object that is one (GD::Text::Align). BUGS
None that I know of, but that doesn't mean much. There may be some problems with exotic fonts, or locales and character encodings that I am not used to. TODO
Angled boxes. At the moment, the only bit of the box that is allowed to be unspecified and in fact must be unspecified, is the bottom. If there is enough need for it, I might implement more flexibility, in that that you need to only specify three of the four sides of the box, and the fourth will be calculated. Automatic resizing of a TrueType font to fit inside a box when four sides are specified, or maybe some other nifty things. More flexibility in the interface. Especially draw needs some thought. More and better error handling. Warnings for lines that are too long and stick out of the box. Warning for emptyish lines? COPYRIGHT
copyright 1999 Martien Verbruggen (mgjv@comdyn.com.au) SEE ALSO
GD, GD::Text, GD::Text::Align perl v5.12.3 2003-02-24 Text::Wrap(3pm)
All times are GMT -4. The time now is 11:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy