Sponsored Content
Top Forums Shell Programming and Scripting Converting columns of text to rows, with blank lines Post 303006990 by lupin..the..3rd on Thursday 9th of November 2017 01:44:35 PM
Old 11-09-2017
Converting columns of text to rows, with blank lines

I've spent the past hour trying different things and googling for this solution and cannot find the answer. Found variations of this, but not this exact thing.

I have the following text, which is the output from our mainframe. Each field is on a separate line, with a blank line between each record. I want to the lines together. A blank line indicates a new row. Note that some of the fields contain slashes, periods, and other punctuation. Also the number of lines to join is variable, but records are always separated by a single blank line.

This is the contents of the source text file:
Code:
7LKZB88901
DC090SDFKGHSDD
REJECT REASON DDP/09/Q
SCC/GO/SEX.M.DNY/ALASKA/ CONTACT THE DENYING AGENCY
For the following
DUPLICATE

7LKZB88902
DC090RDFK1HSDD
PENDING

8PKZB88903
DC0901DFK1HSD7
ACCEPT

7LKZB88901
DC090SDFKGHSDD
REJECT REASON DDP/09/Q
SCC/GO/SEX.M.DNY/ALASKA/ CONTACT THE DENYING AGENCY
For the following
ERROR

5KZZB88912
DC0901DFF1HGG2
ACCEPT

And here's what I want the output to look like:

Code:
7LKZB88901 DC090SDFKGHSDD REJECT REASON DDP/09/Q SCC/GO/SEX.M.DNY/ALASKA/ CONTACT THE DENYING AGENCY For the following DUPLICATE
7LKZB88902 DC090RDFK1HSDD PENDING
8PKZB88903 DC0901DFK1HSD7 ACCEPT
7LKZB88901 DC090SDFKGHSDD REJECT REASON DDP/09/Q SCC/GO/SEX.M.DNY/ALASKA/ CONTACT THE DENYING AGENCY For the following ERROR
5KZ4B88912 DC0901DFF1HGG2 ACCEPT

My script foo isn't powerful enough. Smilie Any help is appreciated with this one. Smilie

Last edited by lupin..the..3rd; 11-09-2017 at 02:49 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to converting rows to columns, bash

I have in file these words: @fraza1 = rw @fraza2 = r @fraza3 = r @fraza4 = r @fraza5 = r @fraza1 = r @fraza6 = r @fraza7 = r @fraza2 = r @fraza8 = r @fraza9 = r ... I would like so that: ,rw,@fraza1 ,r,@fraza2 (2 Replies)
Discussion started by: patrykxes
2 Replies

2. UNIX for Dummies Questions & Answers

Converting columns into rows

Is there anyway to convert columns into raws using awk? (or any other command line):eek::eek::eek::eek::eek::eek::eek::eek::eek: (1 Reply)
Discussion started by: cosmologist
1 Replies

3. Shell Programming and Scripting

converting rows into columns

Hi, I am trying to fetch some values from db and spooling the output to a file. when i query the db for the values, i get the values in following format. PC_1 wf_test1 Test PC_2 wf_test2 Test PC_3 wf_test3 Test But my spool file was created in following format. PC_1 wf_test1 Test... (20 Replies)
Discussion started by: svajhala
20 Replies

4. Shell Programming and Scripting

Converting rows to columns using shell script

I have a script which converts rows to columns. file_name=$1 mailid=$2 #CREATE BACKUP OF ORIGINAL FILE #cp ${file_name}.xlsx ${file_name}_temp.xlsx #tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv #rm ${file_name}_temp.xlsx pivot_row=`head -1 ${file_name}` sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies

5. Shell Programming and Scripting

Perl : blank lines are displayed in the output after deleting few rows from excel

I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations. In this process, I first defined 10 records in excel sheet and executed the below code. In the first run it is OK. But after deleting last few rows in excel sheet and... (0 Replies)
Discussion started by: giridhar276
0 Replies

6. Shell Programming and Scripting

Need to remove a selection of rows separated by blank lines

hello, here is an example: 9.07 9.05 0.00 2.28 0.00 0.08 1.93 3.62 10.97 12.03 12.03 0.00 2.73 0.00 0.07 (3 Replies)
Discussion started by: Baron1
3 Replies

7. Shell Programming and Scripting

Converting rows to columns in csv file

Hi, I have a requirement to convert rows into columns. data looks like: c1,c2,c3,.. r1,r2,r3,.. p1,p2,p3,.. and so on.. output shud be like this: c1,r1,p1,.. c2,r2,p2,.. c3,r3,p3,.. Thanks in advance, (12 Replies)
Discussion started by: Divya1987
12 Replies

8. UNIX for Dummies Questions & Answers

Converting Columns To Rows Sort Of

Hi I'm a UNIX awk and sed novice at best. I'm trying to creat a .csv file so it can be graphed in Excel. Tried various xargs, awk, sed and paste but just can't seem to get the data to line up. Not sure if this is beyond for a question in these forums. Any help would greatly be appreciated. Have... (4 Replies)
Discussion started by: jimmyf
4 Replies

9. UNIX for Dummies Questions & Answers

Converting txt output to rows and columns and send report via mail.

Hi All, I would like to send below output in a tabular column ( xml or excel ) and send a mail. vinay unix anil sql vamsee java request to suggest a solution. (1 Reply)
Discussion started by: Girish19
1 Replies

10. Shell Programming and Scripting

Converting rows into columns

hi all I need a help ..I have a script that takes has command and its output is like below.. a b a v v a c I am assigning the above outputs to a variable .. <variable name> = <command output> problem here is when I echo the variable ..it gives me output like " a b... (3 Replies)
Discussion started by: shankarb
3 Replies
Pod::POM::Node(3)					User Contributed Perl Documentation					 Pod::POM::Node(3)

NAME
Pod::POM::Node - base class for a POM node SYNOPSIS
package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR ); %ATTRIBS = ( indent => 4 ); @ACCEPT = qw( over item begin for text verbatim ); $EXPECT = q( back ); package main; my $list = Pod::POM::Node::Over->new(8); $list->add('item', 'First Item'); $list->add('item', 'Second Item'); ... DESCRIPTION
This documentation describes the inner workings of the Pod::POM::Node module and gives a brief overview of the relationship between it and its derived classes. It is intended more as a guide to the internals for interested hackers than as general user documentation. See Pod::POM for information on using the modules. This module implements a base class node which is subclassed to represent different elements within a Pod Object Model. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); The base class implements the new() constructor method to instantiate new node objects. my $list = Pod::POM::Node::Over->new(); The characteristics of a node can be specified by defining certain variables in the derived class package. The %ATTRIBS hash can be used to denote attributes that the node should accept. In the case of an "=over" node, for example, an "indent" attribute can be specified which otherwise defaults to 4. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS $ERROR ); %ATTRIBS = ( indent => 4 ); The new() method will now expect an argument to set the indent value, or will use 4 as the default if no argument is provided. my $list = Pod::POM::Node::Over->new(8); # indent: 8 my $list = Pod::POM::Node::Over->new( ); # indent: 4 If the default value is undefined then the argument is mandatory. package Pod::POM::Node::Head1; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS $ERROR ); %ATTRIBS = ( title => undef ); package main; my $head = Pod::POM::Node::Head1->new('My Title'); If a mandatory argument isn't provided then the constructor will return undef to indicate failure. The $ERROR variable in the derived class package is set to contain a string of the form "$type expected a $attribute". # dies with error: "head1 expected a title" my $head = Pod::POM::Node::Head1->new() || die $Pod::POM::Node::Head1::ERROR; For convenience, the error() subroutine can be called as a class method to retrieve this value. my $type = 'Pod::POM::Node::Head1'; my $head = $type->new() || die $type->error(); The @ACCEPT package variable can be used to indicate the node types that are permitted as children of a node. package Pod::POM::Node::Head1; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $ERROR ); %ATTRIBS = ( title => undef ); @ACCEPT = qw( head2 over begin for text verbatim ); The add() method can then be called against a node to add a new child node as part of its content. $head->add('over', 8); The first argument indicates the node type. The @ACCEPT list is examined to ensure that the child node type is acceptable for the parent node. If valid, the constructor for the relevant child node class is called passing any remaining arguments as attributes. The new node is then returned. my $list = $head->add('over', 8); The error() method can be called against the parent node to retrieve any constructor error generated by the child node. my $list = $head->add('over', 8); die $head->error() unless defined $list; If the child node is not acceptable to the parent then the add() method returns one of the constants IGNORE, REDUCE or REJECT, as defined in Pod::POM::Constants. These return values are used by the Pod::POM parser module to implement a simple shift/reduce parser. In the most common case, IGNORE is returned to indicate that the parent node doesn't know anything about the new child node. The parser uses this as an indication that it should back up through the parse stack until it finds a node which will accept this child node. Through this mechanism, the parser is able to implicitly terminate certain POD blocks. For example, a list item initiated by a "=item" tag will not accept another "=item" tag, but will instead return IGNORE. The parser will back out until it finds the enclosing "=over" node which will accept it. Thus, a new "=item" implicitly terminates any previous "=item". The $EXPECT package variable can be used to indicate a node type which a parent expects to terminate itself. An "=over" node, for example, should always be terminated by a matching "=back". When such a match is made, the add() method returns REDUCE to indicate successful termination. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR ); %ATTRIBS = ( indent => 4 ); @ACCEPT = qw( over item begin for text verbatim ); $EXPECT = q( back ); package main; my $list = Pod::POM::Node::Over->new(); my $item = $list->add('item'); $list->add('back'); # returns REDUCE If a child node isn't specified in the @ACCEPT list or doesn't match any $EXPECT specified then REJECT is returned. The parent node sets an internal error of the form "$type expected a terminating $expect". The parser uses this to detect missing POD tags. In nearly all cases the parser is smart enough to fix the incorrect structure and downgrades any errors to warnings. # dies with error 'over expected terminating back' ref $list->add('head1', 'My Title') # returns REJECT || die $list->error(); Each node contains a 'type' field which contains a simple string indicating the node type, e.g. 'head1', 'over', etc. The $NODES and $NAMES package variables (in the base class) reference hash arrays which map these names to and from package names (e.g. head1 <=> Pod::POM::Node::Head1). print $list->{ type }; # 'over' An AUTOLOAD method is provided to access to such internal items for those who don't like violating an object's encapsulation. print $list->type(); Nodes also contain a 'content' list, blessed into the Pod::POM::Node::Content class, which contains the content (child elements) for the node. The AUTOLOAD method returns this as a list reference or as a list of items depending on the context in which it is called. my $items = $list->content(); my @items = $list->content(); Each node also contains a content list for each individual child node type that it may accept. my @items = $list->item(); my @text = $list->text(); my @vtext = $list->verbatim(); The present() method is used to present a node through a particular view. This simply maps the node type to a method which is then called against the view object. This is known as 'double dispatch'. my $view = 'Pod::POM::View::HTML'; print $list->present($view); The method name is constructed from the node type prefixed by 'view_'. Thus the following are roughly equivalent. $list->present($view); $view->view_list($list); The benefit of the former over the latter is, of course, that the caller doesn't need to know or determine the type of the node. The node itself is in the best position to determine what type it is. AUTHOR
Andy Wardley <abw@kfs.org> COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Consult Pod::POM for a general overview and examples of use. perl v5.16.3 2010-04-02 Pod::POM::Node(3)
All times are GMT -4. The time now is 04:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy