Solved

how to generate the variable from string with pipe?

Posted on 2011-03-07
6
266 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

25 Experts available now in Live!

Get 1:1 Help Now