Need to understand how the line in perl program works as shell commend


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to understand how the line in perl program works as shell commend
# 1  
Old 05-09-2017
Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value:
Code:
 TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC
D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS
 MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT PRICE|FICC|LAST PRCDT|MARK
ET VALUE|SECURITY TRADING CURRENCY|SRC OF MARK TO MARKET|SETTLEMENT PRICE|SETTLE
MENT PRICE CURRENCY|FORWARD PRICE|REPO RATE|GSCC FLG|MBSCC FLG|SDTR DAYS|COUPON|
DBEI|TTOC|TRNO|CURR FACTOR|TTDOL|ATCD|ISSUE DT|REG SD DAYS|REG STDT|CDBO|TAXID|C
UST NICK|GRP ACT|AINT|AINT FACTOR|SPCD|EXEMPT|AMS CLASS CD|BPS BRKNO|SEC RATING|
SEC RATING VENDOR|SEC RATING ACTUAL|SEC RATING SRC|REG SEC|CONV|SECC|RTID|CRVI|T
DATE|WI IND|LE
AGY TRADES|F348533S14419861@000|F348533S...000|1|AGY|FRED            |ACTI
VE||2420477290|BLACKROCK FINANCIAL MGMT INC|DMG|DMG |C572|20170421|20170421|2017
0629|20170426|S|3137EADH9|CUSIP|FREDDIE MAC 1% 06/29/2017      |28000|USD|100.03
59382|100.0359382|USD||N|20170424||USD|TRDMRK|100.0367   P|||.5| | |0000000005|1
.000000| | |0007557|1.00000000|28101.28|AGY|20120514|1|20170424|O|20-5319476 |BF
M W-PIOMNI|63032       |91.00|3222.22000000|CW3|N        |10029|||MOODY|Aaa|DBI|
 ||USD|201704210007557|   |20170421||LEREC-CNT=000001

I want to cut it by 13, 19,11,24,21,29 fields
Below is line in Perl, which is not working in shell
Code:
 $cmd=("awk -F'|' '{print \$($i_secid+1) \"\|\" \$($i_trdr+1) \"\|\" \$($i_encd+1) \"\|\" \$($i_market_price+1) \"\|\" \$($i_last_prcdt+1) \"\|\" \$($i_secnm+1)}' $if|sort -u");
 `cmd`

I just want to understand what it does, so that make it work in Perl on apache server

Thanks for contribution
# 2  
Old 05-09-2017
What do you mean by:
Quote:
I want to cut it by 13, 19,11,24,21,29 fields
Could you post an example of the output you are looking for?

Perl does not require awk nor sort to do the work. Making outside calls to these other programs indicates that whoever wrote them did not know enough Perl.
# 3  
Old 05-09-2017
It is not mine. We just move it from UNIX to apache , that is why I have to change it. But how? In reality file is huge, 10000 lines. The script was done 10 years ago. I don't even know, what should be the output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to understand special character for line reading in bash shell?

I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters... (3 Replies)
Discussion started by: duke0001
3 Replies

2. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

3. Programming

Please help me understand errors in perl program

co #! /usr/bin/perl use strict; use warnings; use diagnostics; my $amount=""; my $bain; ; my $code=""; my $date;my $day;my $line; my $mo; my $LNUM = 0; my $xyz=""; my $yr; $yr = 2015; my $F; my @F; while (<>) { chop; ++$LNUM; @F = split(';'); if ( $F eq "Date" )... (1 Reply)
Discussion started by: hpk
1 Replies

4. Shell Programming and Scripting

I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works

Please help me understand how sort -k3,3 -k 4,4 short* works , is it sorting 3 and 4 th field ? what is the use of specifying 3,3 and 4,4 in sort and what is actually does and i see sort -k3 short* and sort -k3,3 -k 4,4 short* giving the same output. Sort output attached Please help (2 Replies)
Discussion started by: Antony Ankrose
2 Replies

5. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

6. Shell Programming and Scripting

Convert perl program to shell

Hi is there a way that i can convert this simple perl program into shell script #!usr/bin/perl -w use strict; use warnings; open INPUTFILE, "uniqprobecoordinates.out" || die "canot open the file $!"; open OUTPUTFILE, ">", "1_4reads.out"; while(<INPUTFILE>) { chomp; ... (3 Replies)
Discussion started by: bhargavpbk88
3 Replies

7. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

8. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

9. Shell Programming and Scripting

Run shell program in perl

Hello , I want to run some shell scripts in my perl script. I need to read the script's name from a file ( this file includes the name of all the scripts) and run the script one by one.. Please let me know how to go .. Thanks in advance, Radha (5 Replies)
Discussion started by: s123.radha
5 Replies

10. Shell Programming and Scripting

Line works in solo but not in program?

Now I am just getting frustrated and confused... if anyone has some advice on how this anomoly is occurring I would greatly appreciate it. cat helpme.txt | awk 'NR<5{printf("%-20s %-20d %-20d %-20.1f\n","hello",$1,$2,$3)}' | sort -rk4 This line works fine in solo - reads the three fields from... (4 Replies)
Discussion started by: nortypig
4 Replies
Login or Register to Ask a Question