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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-25-2017, 06:33 PM
|
#1
|
LQ Newbie
Registered: Jun 2017
Posts: 1
Rep:
|
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.
|
|
|
06-25-2017, 08:22 PM
|
#2
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,018
|
Sounds like a good little problem. What have you done in an attempt to solve this and where are you stuck?
|
|
|
06-25-2017, 09:57 PM
|
#3
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,251
|
Quote:
Originally Posted by sam.987
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.
|
|
|
All times are GMT -5. The time now is 02:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|