Solved

how to generate the variable from string with pipe?

Posted on 2011-03-07
6
267 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
  • 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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