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
ARRAY_FLIP(3)								 1							     ARRAY_FLIP(3)

array_flip - Exchanges all keys with their associated values in an array

SYNOPSIS
array array_flip (array $array) DESCRIPTION
array_flip(3) returns an array in flip order, i.e. keys from $array become values and values from $array become keys. Note that the values of $array need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be included in the result. If a value has several occurrences, the latest key will be used as its value, and all others will be lost. PARAMETERS
o $array - An array of key/value pairs to be flipped. RETURN VALUES
Returns the flipped array on success and NULL on failure. EXAMPLES
Example #1 array_flip(3) example <?php $input = array("oranges", "apples", "pears"); $flipped = array_flip($input); print_r($flipped); ?> The above example will output: Array ( [oranges] => 0 [apples] => 1 [pears] => 2 ) Example #2 array_flip(3) example : collision <?php $input = array("a" => 1, "b" => 1, "c" => 2); $flipped = array_flip($input); print_r($flipped); ?> The above example will output: Array ( [1] => b [2] => c ) SEE ALSO
array_values(3), array_keys(3), array_reverse(3). PHP Documentation Group ARRAY_FLIP(3)
All times are GMT -4. The time now is 10:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy