Solved

how to generate the variable from string with pipe?

Posted on 2011-03-07
6
265 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now