Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to generate the variable from string with pipe?

Posted on 2011-03-07
6
Medium Priority
?
274 Views
Last Modified: 2012-05-11
How to print the each value in the PIPE?
I got the string like this ->>>>

AAA="|382200000 |0  |                                        |2.30        |KG     |            |       |3893.00           |        |                  |   |   |
 |   |   |      |       |     |  |       |
|300210000 |6  |                                        |2.60        |KG     |            |       |3948.00           |        |                  |   |   |
|   |   |      |       |     |  |       |

(2 rows affected)
(return status = 0)"

i need to print it

382200000 ^M
0 ^M
                   ^M
2.30      ^M
KG  ^M

until last one

     ^M


any idea for this?
0
Comment
Question by:gagajanice
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35065879
Does this little PERL script do what you want?



$AAA=q{|382200000 |0  |                                        |2.30        |KG     |            |       |3893.00          |        |                  |   |   | |   |   |      |       |     |  |       |
|300210000 |6  |                                        |2.60        |KG     |            |       |3948.00           |       |                  |   |   | |   |   |      |       |     |  |       |
};

$AAA =~ s/[\r\n]//g;    
@x = split(/\|/, $AAA);
shift(@x);      # first entry is null
print join("^M\n", @x);

Open in new window



perl foo.pl
382200000 ^M
0  ^M
                                        ^M
2.30        ^M
KG     ^M
            ^M
       ^M
3893.00          ^M
        ^M
                  ^M
   ^M
   ^M
 ^M
   ^M
   ^M
      ^M
       ^M
     ^M
  ^M
       ^M
^M
300210000 ^M
6  ^M
                                        ^M
2.60        ^M
KG     ^M
            ^M
       ^M
3948.00           ^M
       ^M
                  ^M
   ^M
   ^M
 ^M
   ^M
   ^M
      ^M
       ^M
     ^M
  ^M

Open in new window

0
 

Author Comment

by:gagajanice
ID: 35065903
thankx.. i need the bash script one... do u know?
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35065905
Improved version:

$AAA=q{|382200000 |0  |                                        |2.30        |KG     |            |       |3893.00          |        |                  |   |   | |   |   |      |       |     |  |       |
|300210000 |6  |                                        |2.60        |KG     |            |       |3948.00           |       |                  |   |   | |   |   |      |       |     |  |       |


(2 rows affected)
(return status = 0)"

};


@a = split(/[\r\n]+/, $AAA);
foreach $a (@a) { while ( $a =~ s/^\|([^\|]*)\|/\|/ ) { print "$1^M\n"; } }

Open in new window

0
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

 
LVL 16

Expert Comment

by:sjklein42
ID: 35065912
Sorry, not a basher.
0
 

Author Comment

by:gagajanice
ID: 35065918
oic... thank you so much!
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 35066455
#!/bin/bash
AAA="|382200000 |0  |                                        |2.30        |KG     |            |       |3893.00           |        |                  |   |   |
 |   |   |      |       |     |  |       |
|300210000 |6  |                                        |2.60        |KG     |            |       |3948.00           |        |                  |   |   |
|   |   |      |       |     |  |       |

(2 rows affected)
(return status = 0)"

echo "${AAA//|/
}"
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question