Sponsored Content
Full Discussion: Insert blank line in a file
Top Forums Shell Programming and Scripting Insert blank line in a file Post 302418387 by yoursdivu on Tuesday 4th of May 2010 07:03:51 AM
Old 05-04-2010
Insert blank line in a file

I have a file with data as below :

Code:
Heading 1
-------------
Heading 1 data1
Heading 1 data2
Heading 1 data3
Heading 1 data4
Heading 2
-------------
Heading 2 data1
Heading 2 data2
Heading 2 data3
Heading 2 data4
Heading 3
-------------
Heading 3 data1
Heading 3 data2
Heading 3 data3
Heading 3 data4

I want to insert a blank line after each set of Heading.
ie; The data should look as below.
Code:
Heading 1
-------------
Heading 1 data1
Heading 1 data2
Heading 1 data3
Heading 1 data4

Heading 2
-------------
Heading 2 data1
Heading 2 data2
Heading 2 data3
Heading 2 data4

Heading 3
-------------
Heading 3 data1
Heading 3 data2
Heading 3 data3
Heading 3 data4

How can we do this using awk/sed.
We can use --- for pattern search if required.

Thanks

Last edited by vgersh99; 05-04-2010 at 08:07 AM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert blank line if grep not found

Hello everyone... please help if you can -- I'm stumped. Making this work will save me hours of manual labor: I need to search file2 for pattern in file1. If pattern found append file2 line to file3. If pattern not found append a blank line to file3. file1 contents example: 123 456 789... (6 Replies)
Discussion started by: michieka
6 Replies

2. Shell Programming and Scripting

insert text and add blank line

I need your help, I want to add a text every 2nd line and also a blank line after 3 line (In the output 2nd line is "changetype: modify" and every 4th line is blank line) Input file format dn: abc orclsourceobjectdn: abcd dn: bcd orclsourceobjectdn: bcda dn: cba orclsourceobjectdn:... (7 Replies)
Discussion started by: athidhi
7 Replies

3. Shell Programming and Scripting

compare three files and insert a blank line at each mismatch

i need to compare three files in unix a.txt b.txt c.txt 1 2 1 2 5 3 4 6 5 5 6 6 i need to insert a blank line in the file if i don't find a match and put the items at the same column if found a match The items in the files... (4 Replies)
Discussion started by: mad_man12
4 Replies

4. Shell Programming and Scripting

Insert blank line if grep not found

Hi all, I've googling around forum regarding my prob, the nearest would same as thread tittled Insert blank line if grep not found, but she/he did not mention the solution, so I would like to request your help I've this task, to search in file2 based on pattern in file1 and output it to... (4 Replies)
Discussion started by: masterpiece
4 Replies

5. Shell Programming and Scripting

insert blank line between lines

Hello, I am trying to write a script that will count the number of characters for each line in a file and all the lines that have less than 80 characters and that are ending with a period, I want it to insert a blank line after them immediately. But, for whatever reason the condition if ]] is... (3 Replies)
Discussion started by: Pouchie1
3 Replies

6. Shell Programming and Scripting

sort with condition and insert blank line

Hi, I have a file with no blank line anywhere Its a conf file, The lines between and starts with "#" should be sort out with the first three characters(characters are between (a-z)). and insert a blank space in between the uniq lines. For clear understanding ,pls find the below input file... (11 Replies)
Discussion started by: anil8103
11 Replies

7. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

8. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

9. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

10. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies
composite(3)						User Contributed Perl Documentation					      composite(3)

NAME
Tk::composite - Defining a new composite widget class SYNOPSIS
package Tk::MyNewWidget; use Tk:widgets qw/ list of Tk widgets /; use base qw/ Tk::Frame /; # or Tk::Toplevel Construct Tk::Widget 'MyNewWidget'; sub ClassInit { my( $class, $mw ) = @_; #... e.g., class bindings here ... $class->SUPER::ClassInit( $mw ); } sub Populate { my( $self, $args ) = @_; my $flag = delete $args->{-flag}; if( defined $flag ) { # handle -flag => xxx which can only be done at create # time the delete above ensures that new() does not try # and do $self->configure( -flag => xxx ); } $self->SUPER::Populate( $args ); $self = $self->Component( ... ); $self->Delegates( ... ); $self->ConfigSpecs( '-cursor' => [ SELF, 'cursor', 'Cursor', undef ], '-something' => [ METHOD, dbName, dbClass, default ], '-text' => [ $label, dbName, dbClass, default ], '-heading' => [ {-text => $head}, heading, Heading, 'My Heading' ], ); } sub something { my( $self, $value) = @_; if ( @_ > 1 ) { # set it } return # current value } 1; __END__ =head1 NAME Tk::Whatever - a whatever widget =head1 SYNOPSIS use Tk::Whatever; $widget = $parent->Whatever(...); =head1 DESCRIPTION ... DESCRIPTION
The intention behind a composite is to create a higher-level widget, sometimes called a "super-widget" or "mega-widget". Most often, a composite will be built upon other widgets by using them, as opposed to specializing on them. For example, the supplied composite widget LabEntry is made of an Entry and a Label; it is neither a kind-of Label nor is it a kind-of Entry. Most of the work of a composite widget consistd in creating subwidgets, arranging to dispatch configure options to the proper subwidgets and manage composite-specific configure options. GLORY DETAILS
Depending on your Perl/Tk knowledge this section may be enlighting or confusing. Composite Widget Since Perl/Tk is heavilly using an object-oriented approach, it is no suprise that creating a composite goes through a new() method. However, the composite does not normally define a new() method itself: it is usually sufficient to simply inherit it from Tk::Widget. This is what happens when the composite uses use base qw/ Tk::Frame /; # or Tk::Toplevel to specify its inheritance chain. To complete the initialisation of the widget, it must call the Construct method from class Widget. That method accepts the name of the new class to create, i.e. the package name of your composite widget: Construct Tk::Widget 'MyNewWidget'; Here, MyNewWidget is the package name (aka the widget's class). This will define a constructor method for MyNewWidget, normally named after the widget's class. Instanciating that composite in client code would the look like: $mw = MainWindow->new; # creates a top-level MainWindow $self = $mw->MyNewWidget(); # creates an instance of the # composite widget MyNewWidget Whenever a composite is instanciated in client code, "Tk::Widget::new()" will be invoked via the widget's class constructor. That new method will call $self->Populate(\%args); where %args is the arguments passed to the widget's constructor. Note that Populate receives a reference to the hash array containing all arguments. Populate is typically defined in the composite class (package), which creates the characteristic subwidgets of the class. Creating Subwidgets Subwidget creation happens usually in Populate(). The composite usually calls the subwidget's constructor method either directly, for "private" subwidgets, or indirectly through the Component method for subwidgets that should be advertised to clients. Populate may call Delegates to direct calls to methods of chosen subwidgets. For simple composites, typically most if not all methods are directed to a single subwidget - e.g. ScrListbox directs all methods to the core Listbox so that $composite->get(...) calls $listbox->get(...). Defining mega-widget options Populate should also call ConfigSpecs() to specify the way that configure-like options should be handled in the composite. Once Populate returns, method Tk::Frame::ConfigDefault walks through the ConfigSpecs entries and populates %$args hash with defaults for options from X resources (.Xdefaults, etc). When Populate returns to Tk::Widget::new(), a call to $self->configure(%$args) is made which sets *all* the options. SEE ALSO
Tk::ConfigSpecs Tk::mega Tk::Derived perl v5.16.3 2014-06-10 composite(3)
All times are GMT -4. The time now is 08:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy