Perl string formation from array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl string formation from array
# 1  
Old 12-07-2012
Perl string formation from array

HI I ma using perl programming

my perl is like this

Code:
 
$InputFile = $ENV{UDE_TMP} . "/" ."cre_fmr_gen.temp_data_file_gen.dat";
@duplicates = `cat $InputFile | cut -d "|" -f 1,1 | sort | uniq -c | awk '{ if(\$1>1) {print \$2;}}'`;
my $cusiplist ;
foreach $cusip (@duplicates)
{
print("instrument is   $cusip"); 
$cusiplist = $cusiplist . "|" . $cusip  ;
}
print($cusiplist);
$tmp_file_1 = $ENV{UDE_TMP} . "/" ."prabhu1";
$tmp_file_2 = $ENV{UDE_TMP} . "/" ."prabhu2";
print($tmp_file_2 );
#$InputFile = $ENV{UDE_TMP} . "/" ."cre_fmr_gen.temp_data_file_gen.dat";
print ("$InputFile ");
use File::Copy;
copy( "$InputFile" , "$InputFile.CP.Prabhu");
$cmd = `cat $InputFile | egrep '$cusiplist'  > $tmp_file_1`;
#$cmd= `cat $InputFile  >$tmp_file_I`;
system(cmd);
print($cmd);

so now i am getting the out put as

Code:
instrument is   FN110OY12
instrument is   FN112OY10
instrument is   FN112OY11
instrument is   FN112OY12
instrument is   FN114OY03
instrument is   FN114OY09
instrument is   FN114OY10
instrument is   FN114OY11
instrument is   FN114OY12
instrument is   FN116OY03
instrument is   FN116OY04
instrument is   FN116OY05
instrument is   FN116OY09
instrument is   FN116OY10
instrument is   FN118OY03
instrument is   FN118OY04
instrument is   FN118OY05
instrument is   FN118OY08
instrument is   FN118OY09
instrument is   FN118OY10
instrument is   FN120OY03
instrument is   FN120OY08
instrument is   FN122OY05
instrument is   FN122OY07
instrument is   FN124OY08
|FN110OY12
|FN112OY10
|FN112OY11
|FN112OY12
|FN114OY03
|FN114OY09
|FN114OY10
|FN114OY11
|FN114OY12
|FN116OY03
|FN116OY04
|FN116OY05
|FN116OY09
|FN116OY10
|FN118OY03
|FN118OY04
|FN118OY05
|FN118OY08
|FN118OY09
|FN118OY10
|FN120OY03
|FN120OY08
|FN122OY05
|FN122OY07
|FN124OY08
/itf/ude/tmp/prabhu2/itf/ude/tmp/cre_fmr_gen.temp_data_file_gen.dat

But I wanted to make a string like this

'FN112OY12|FN114OY10|FN116OY03|FN116OY04|FN116OY05|FN118OY03|FN118OY04|FN118OY05|FN118OY08|FN118OY10 |FN120OY02
|FN120OY08|FN122OY05|FN124OY08'


what needs to be done?
# 2  
Old 12-07-2012
Well, you need to remove the first pipe mark or not append a pipe on the first item, and it seems you are carrying forward a line feed on the right side of every cusip, nice for the instrument is line but a probem for the desired long line. Beginner's Introduction to Perl - Perl.com PERL print does not add or remove line feeds.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

2. Programming

Not a repeated question (Perl Script Create Football Formation)

https://www.unix.com/programming/252468-perl-script-create-football-formation.html https://www.unix.com/members/43551.html, it is not repeated question. please read it before u block my question. Unblock it for me. Thanks:mad: (0 Replies)
Discussion started by: Tzeronone
0 Replies

3. Programming

Perl script to create football formation

I need help to create varieties of football formation. The available positions are: GK SW DR DC DL WBR DM WBL MR MC ML AMR AMC AML ST But the conditions are: a. the maximum number in 1 formation: GK is 1 SW is 1 (1 Reply)
Discussion started by: Tzeronone
1 Replies

4. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

5. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

6. Shell Programming and Scripting

[Perl] Sorting an String-Array

Hi, i have a txtfile with the format <Nr>tab<word>tab<other stuff>new line and i want to sort the <word>-colum with a perl script. My textfile: <Nr>tab<word>tab<other stuff>new line 6807 die ART.Acc.Sg.Fem 6426 der ART.Gen.Sg.Fem 2 die ART.Nom.Sg.Fem 87 auf APPR.-- 486 nicht PTKNEG.--... (1 Reply)
Discussion started by: buckelede
1 Replies

7. Shell Programming and Scripting

Perl and string array problem

#!/usr/bin/perl my @arr=("hello", "how", "are", "you"); $l=length(@arr); print $l; This print 1.Why? How can i print the array size = 4? I want to store these in an array. hello how are you And then i want to access these element through indexing. How can i do this? (4 Replies)
Discussion started by: cola
4 Replies

8. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

9. Shell Programming and Scripting

search of string from an array in Perl

Hi All I want to search a string from an array in Perl. If a match occurs, assign that string to a variable else assign 'No match'. I tried writing the script as follows but it's in vain. Please help me.. #!/usr/bin/perl use strict; my $NER; my @text=("ORG","PER"); ... (4 Replies)
Discussion started by: my_Perl
4 Replies

10. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies
Login or Register to Ask a Question