Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Remove line breaks and extra spaces Post 302999571 by rsi.245 on Thursday 22nd of June 2017 03:05:36 PM
Old 06-22-2017
Remove line breaks and extra spaces

Hi,
I want to remove all extra spaces, line breaks .
Need a new line entry only for term starting"array"

For eg: my input is
Code:
array([ 0.03015278,  0.02738889,  0.0125    ,  0.00875   ,  0.00736806,
        0.00672917,  0.00763889,  0.01044444,  0.01178472,  0.01470139,
        0.02020833,  0.03288194,  0.05940278,  0.03489583,  0.01829167,
        0.01255556,  0.00811111,  0.00670139,  0.00543056,  0.00570139,
        0.00616667,  0.00821528,  0.01138889,  0.02573611,  0.03044444,
        0.57640972]), 
array([ 0.03372518,  0.03230408,  0.00867816,  0.00548067,  0.00434692,
        0.00423197,  0.00397074,  0.0049373 ,  0.00669279,  0.01053292,
        0.0149373 ,  0.02205329,  0.03096134,  0.01904389,  0.009279  ,
        0.00683386,  0.00335946,  0.00386102,  0.00250261,  0.0030303 ,
        0.00272727,  0.00426332,  0.00734587,  0.03399164,  0.05005747,
        0.67085162]), 
array([ 0.035     ,  0.03807317,  0.01169512,  0.00759146,  0.00479878,
        0.00514634,  0.0037378 ,  0.00606707,  0.00528049,  0.00892683,
        0.00631707,  0.01397561,  0.01756098,  0.0159939 ,  0.00477439,
        0.00714024,  0.00343293,  0.00530488,  0.00282927,  0.00380488,
        0.00390854,  0.00551829,  0.00696951,  0.03689634,  0.0427439 ,
        0.6965122 ]),


and my expected output is

Code:
array([ 0.03015278, 0.02738889, 0.0125 , 0.00875 , 0.00736806, 0.00672917, 0.00763889, 0.01044444, 0.01178472, 0.01470139, 0.02020833, 0.03288194, 0.05940278, 0.03489583, 0.01829167, 0.01255556, 0.00811111, 0.00670139, 0.00543056, 0.00570139, 0.00616667, 0.00821528, 0.01138889, 0.02573611, 0.03044444, 0.57640972]), 
array([ 0.03372518, 0.03230408, 0.00867816, 0.00548067, 0.00434692, 0.00423197, 0.00397074, 0.0049373 , 0.00669279, 0.01053292, 0.0149373 , 0.02205329, 0.03096134, 0.01904389, 0.009279 , 0.00683386, 0.00335946, 0.00386102, 0.00250261, 0.0030303 , 0.00272727, 0.00426332, 0.00734587, 0.03399164, 0.05005747, 0.67085162]), 
array([ 0.035 , 0.03807317, 0.01169512, 0.00759146, 0.00479878, 0.00514634, 0.0037378 , 0.00606707, 0.00528049, 0.00892683, 0.00631707, 0.01397561, 0.01756098, 0.0159939 , 0.00477439, 0.00714024, 0.00343293, 0.00530488, 0.00282927, 0.00380488, 0.00390854, 0.00551829, 0.00696951, 0.03689634, 0.0427439 , 0.6965122 ]),

Is it possible using awk?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To remove the extra spaces in unix

Hi... I am quite new to Unix and would like an issue to be resolved. I have a file in the format below; 4,Reclaim,ECXTEST02,abc123,Harry Potter,5432 6730 0327 5469,0603,,MC,,1200,EUR,sho-001,,1,,,abc123,1223 I would like my output to be as follows; 4,Reclaim,ECXTEST02,abc123,Harry... (4 Replies)
Discussion started by: Sho
4 Replies

2. Shell Programming and Scripting

Remove extra spaces in a line

Hi, I need a help in deleting extra spaces in a text. I have a huge file, a part of it is :- 3 09/21/08 03:32:07 started undef mino Oracle nmx004.wwdc.numonyx.com Message Text : The Oracle session with the PID 1103 has a CPU time ... (6 Replies)
Discussion started by: vikas027
6 Replies

3. Shell Programming and Scripting

any better way to remove line breaks

Hi, I got some log files which print the whole xml message in separate lines: e.g. 2008-10-01 14:21:44,561 INFO do something 2008-10-01 14:21:44,561 INFO print xml : <?xml version="1.0" encoding="UTF-8"?> <a> <b>my data</b> </a> 2008-10-01 14:21:44,563 INFO do something again I want... (3 Replies)
Discussion started by: csmklee
3 Replies

4. Shell Programming and Scripting

remove extra spaces between fields

Hi, I have a source file as mentioned below: I want to remove all the extra spaces between the fields. a b--------|sa df-------|3232---|3 sf sa------|afs sdf-----|43-----|33 a b c------|adfsa dsf---|23-32|23 *Here '-' idicates spaces Now, I want output as below: a b|sa df|3232|3... (7 Replies)
Discussion started by: srilaxmi
7 Replies

5. Shell Programming and Scripting

How to remove extra spaces from a string??

Hi, I have a string like this and i want to remove extra spaces that exists between the words. Here is the sentence. $string="The small DNA genome of hepadnaviruses is replicated by reverse transcription via an RNA intermediate. This RNA "pregenome" contains ... (2 Replies)
Discussion started by: vanitham
2 Replies

6. Shell Programming and Scripting

Remove of extra spaces from the trailing

HI, I need the help from the experts like I have created one file with text like: a b c d e f g h i j k l So my question is that i have to write the script in which like in the first sentence it will take only one space after d and remove all the extra space in the end.I dont... (8 Replies)
Discussion started by: bhanudhingra
8 Replies

7. Shell Programming and Scripting

Remove line breaks after a match

I need to remove all line breaks in a document after a match, until there is a blank line. Example below, after the match "THE GREEN TABLE" remove line breaks until a blank line. Then, after the match "THE BLUE TABLE" do the same. Before: THE GREEN TABLE Lorem ipsum dolor sit amet,... (14 Replies)
Discussion started by: dockline
14 Replies

8. Shell Programming and Scripting

Delete line breaks and extra spaces between patterns

Hi, if in between strings "<section" and "</section>" across multiple lines there occurs the string "ole-present", delete all line breaks and replace any tabs or multiple spaces with a single space. Looking for an AWK or SED solution. Thank you. <section ... status = "ole-present" ...... (2 Replies)
Discussion started by: pioavi
2 Replies

9. UNIX Desktop Questions & Answers

To remove the extra spaces at the end of each line in a file

I have a file of about 10k records and eace line is having an extra space of 5 byte at the end.. Iwant to remove the extra spaces at the end of each line.. Can someone please help me out.. I tried using sed command and its not working... can someone please help me out. (3 Replies)
Discussion started by: rammohan
3 Replies

10. Shell Programming and Scripting

Remove single-line breaks only in document

Regarding copy/pasted text of copyright-free book from archive.org (link below), in attempt to expand single-line-break paragraph text (not section headings or paragraph breaks) to wider right margin, Justify or Wrap in LIbreOffice is not working, and Find/Replace the paragraph mark ($) wraps all... (2 Replies)
Discussion started by: p1ne
2 Replies
Tree::Simple::Visitor::ToNestedArray(3pm)		User Contributed Perl Documentation		 Tree::Simple::Visitor::ToNestedArray(3pm)

NAME
Tree::Simple::Visitor::ToNestedArray - A Visitor for creating nested array trees from Tree::Simple objects. SYNOPSIS
use Tree::Simple::Visitor::ToNestedArray; my $visitor = Tree::Simple::Visitor::ToNestedArray->new(); # given this Tree::Simple tree my $tree = Tree::Simple->new("Root") ->addChildren( Tree::Simple->new("Child1") ->addChildren( Tree::Simple->new("GrandChild1"), Tree::Simple->new("GrandChild2") ), Tree::Simple->new("Child2"), ); # include the trunk (Root) $visitor->includeTrunk(1); # visit the tree $tree->accept($visitor); my $array_tree = $visitor->getResults(); # this then creates the equivalent nested array tree: # [ # 'Root', [ # 'Child1', [ # 'GrandChild1', # 'GrandChild2' # ], # 'Child2' # ] # ] # if you don't include the trunk (Root) then ... $tree->accept($visitor); my $array_tree = $visitor->getResults(); # this then creates the following nested array tree: # [ # 'Child1', [ # 'GrandChild1', # 'GrandChild2' # ], # 'Child2' # ] DESCRIPTION
Given a tree constructed from a Tree::Simple heirarchy, this Visitor will create the equivalent tree of nested arrays. METHODS
new There are no arguments to the constructor the object will be in its default state. You can use the "setNodeFilter" and "includTrunk" methods to customize its behavior. includTrunk ($boolean) Setting the $boolean value to true(1) will cause the node value of the tree's root to be included in the nested array output, setting it to false will do the opposite. setNodeFilter ($filter_function) This method accepts a CODE reference as its $filter_function argument and throws an exception if it is not a code reference. This code reference is used to filter the tree nodes as they are placed into the array tree. The $filter_function is passed a Tree::Simple object, and is expected to return the value desired for inclusion into the array tree. visit ($tree) This is the method that is used by Tree::Simple's "accept" method. It can also be used on its own, it requires the $tree argument to be a Tree::Simple object (or derived from a Tree::Simple object), and will throw and exception otherwise. getResults This method will return the array tree constructed. BUGS
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. CODE COVERAGE
See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more inforamtion. SEE ALSO
These Visitor classes are all subclasses of Tree::Simple::Visitor, which can be found in the Tree::Simple module, you should refer to that module for more information. AUTHOR
stevan little, <stevan@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2004, 2005 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2005-07-14 Tree::Simple::Visitor::ToNestedArray(3pm)
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy