LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2017, 06:33 PM   #1
sam.987
LQ Newbie
 
Registered: Jun 2017
Posts: 1

Rep: Reputation: Disabled
remove line spaces and add new line entry for array


Hi.

Is there a way to remove line break and extra spaces using awk or sed?


My input file is
Code:
[array([ 0.02845476,  0.02685638,  0.01360762,  0.01018389,  0.00817233,
        0.00769514,  0.00766023,  0.00871935,  0.00992978,  0.01282394,
        0.01833876,  0.03112197,  0.04668878,  0.03155843,  0.01698091,
        0.01226917,  0.00854671,  0.00798805,  0.00596485,  0.00646532,
        0.00658752,  0.00882022,  0.01276575,  0.03148277,  0.03787438,
        0.58244297]), 
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 ]),
 array([ 0.04180773,  0.037372  ,  0.01278474,  0.0072884 ,  0.00573145,
        0.00536573,  0.0049791 ,  0.00514629,  0.0049373 ,  0.00582027,
        0.00749216,  0.00933124,  0.01535005,  0.01035528,  0.00504702,
        0.00487983,  0.00304598,  0.00344828,  0.00279519,  0.00337513,
        0.00361024,  0.00460293,  0.00856844,  0.0260815 ,  0.10672414,
        0.65405956]), 
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]),
And my expected output is:
Quote:
array([ 0.02845476, 0.02685638, 0.01360762, 0.01018389, 0.00817233, 0.00769514, 0.00766023, 0.00871935, 0.00992978, 0.01282394,0.01833876, 0.03112197, 0.04668878, 0.03155843, 0.01698091, 0.01226917, 0.00854671, 0.00798805, 0.00596485, 0.00646532, 0.00658752, 0.00882022, 0.01276575, 0.03148277, 0.03787438, 0.58244297]),
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]),
array([ 0.04180773, 0.037372 , 0.01278474, 0.0072884 , 0.00573145,0.00536573, 0.0049791 , 0.00514629, 0.0049373 , 0.00582027, 0.00749216, 0.00933124, 0.01535005, 0.01035528, 0.00504702, 0.00487983, 0.00304598, 0.00344828, 0.00279519, 0.00337513, 0.00361024, 0.00460293, 0.00856844, 0.0260815 , 0.10672414, 0.65405956]),
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]),
Aiming to remove line spaces and start a new line for every appearance of string "array"

Last edited by sam.987; 06-25-2017 at 07:24 PM.
 
Old 06-25-2017, 08:22 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Sounds like a good little problem. What have you done in an attempt to solve this and where are you stuck?
 
Old 06-25-2017, 09:57 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
Quote:
Originally Posted by sam.987 View Post
Is there a way to remove line break and extra spaces using awk or sed?
Surely. If the data are always that well structured, fairly straightforward with sed, else any of the scripting languages will do it. Awk included.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Remove extra spaces in a line vikas027 Programming 11 10-11-2008 08:20 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
remove all spaces from a line in C xeon123 Programming 12 10-23-2007 01:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration