Link to home
Start Free TrialLog in
Avatar of gagajanice
gagajanice

asked on

how to generate the variable from string with pipe?

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?
Avatar of sjklein42
sjklein42
Flag of United States of America image

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

Avatar of gagajanice
gagajanice

ASKER

thankx.. i need the bash script one... do u know?
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

Sorry, not a basher.
oic... thank you so much!
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial