Sponsored Content
Top Forums Shell Programming and Scripting Passing multiple value in a single argument in Perl. Post 302930213 by drl on Wednesday 31st of December 2014 12:59:24 PM
Old 12-31-2014
Hi.

This worked for me, assuming that the column string values are enclosed in quotes:
Code:
#!/usr/bin/perl
#This script is to pick the specific fields from a files starting from a specific row
# FILE -> Name of the file to be pasd at runtime.
# rn -> Number of the row from where the data has to be picked.
use strict;
use warnings;
my $file = shift || "FILE";
my $rn   = shift;
my $cols = shift;
open( my $fh, "<", $file ) or die "Could not open file '$file' : $!\n";
print "debug, reading columns :$cols: from $file at line $rn\n";

while (<$fh>) {
  $. <= $rn and next;
  my @fields = split(/\t/);
  # print "$fields[$cols]\n"; #Fails, need @, not $
  # print "@fields[0, 1, 3..6]\n"; #OK
  # print "@fields[0, 3]\n"; #OK
  # print "@fields[0,1,3..6,7]\n"; #OK
  # print @fields[$cols],"\n"; #Fails
  print join( "\t", @fields[ eval($cols) ] ), "\n";    #OK
}

Assuming this works for you, next time please include a short sample input and expected output. It's a pain for responders to create data files that may or may not match what you are working with.

Best wishes ... cheers, drl

Last edited by drl; 12-31-2014 at 02:05 PM..
This User Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

2. UNIX for Dummies Questions & Answers

Using * when passing argument to alias

I have some folders with this structure: /data/me/a123xxx Where "xxx" is some changing series of letters, and "123" changes so folders might look like: /data/me/a123xxx /data/me/a234ysd /data/me/a534sds etc. The numbers are what matter to me (they identify the folder), so I created an... (7 Replies)
Discussion started by: ramparts
7 Replies

3. Shell Programming and Scripting

Help with Passing argument and testing

Hi all First of all thanks for everyone to read by doubt.Am beginner in shell scripting Following are my doubts i have to pass an argument to shellscript how can i do that second i have to test the argument and shows error when nothing is passes third i have to match exact argument... (3 Replies)
Discussion started by: zeebala1981
3 Replies

4. Shell Programming and Scripting

passing either of argument, not both in shell

Hi, I have a requirement to work on script, it should take either of arguments. wrote it as below. #!/bin/bash usage() { echo "$0: missing argument OR invalid option ! Usage : $0 -m|-r|-d } while getopts mrdvh opt; do case "$opt" in m) monitor_flag=monitor;;... (1 Reply)
Discussion started by: ramanaraoeee
1 Replies

5. Programming

PERL:Combining multiple lines to single line

Hi All I need a small help for the below format in making a small script in Perl or Shell. I have a file in which a single line entries are broken into three line entries. Eg: I have a pen and notebook. All i want is to capture in a single line in a separate file. eg: I have a pen and... (4 Replies)
Discussion started by: Kalaiela
4 Replies

6. Shell Programming and Scripting

passing argument from one function to another

Hi all, In the given script code . I want to pass the maximum value that variable "i" will have in function DivideJobs () to variable $max of function SubmitCondorJob(). Any help? Thanks #!/bin/bash ... (55 Replies)
Discussion started by: nrjrasaxena
55 Replies

7. Shell Programming and Scripting

Help with passing argument

Hi, I have a script that is scheduled with cron and runs every night. The cron part looks like this: 00 20 * * 0,1,2,3,4,5,6 /usr/local/bin/BACKUP TBTARM HOT DELETE My issue is with the 3rd parameter. Somewhere in the script, i want to tell the script to delete some files if the 3rd... (7 Replies)
Discussion started by: dollypee
7 Replies

8. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

9. Shell Programming and Scripting

Tabbed multiple csv files into one single excel file with using shell script not perl

Hi Experts, I am querying backup status results for multiple databases and getting each and every database result in one csv file. so i need to combine all csv files in one excel file with separate tabs. I am not familiar with perl script so i am using shell script. Could anyone please... (4 Replies)
Discussion started by: ramakrk2
4 Replies

10. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies
mlib_SignalConvertShift_F32_U8(3MLIB)									     mlib_SignalConvertShift_F32_U8(3MLIB)

NAME
mlib_SignalConvertShift_F32_U8, mlib_SignalConvertShift_F32_S8, mlib_SignalConvertShift_F32_S16, mlib_SignalConvertShift_F32_S32, mlib_Sig- nalConvertShift_F32S_U8S, mlib_SignalConvertShift_F32S_S8S, mlib_SignalConvertShift_F32S_S16S, mlib_SignalConvertShift_F32S_S32S - data type convert with shifting SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_SignalConvertShift_F32_U8(mlib_f32 *dst, const mlib_u8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S8(mlib_f32 *dst, const mlib_s8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S16(mlib_f32 *dst, const mlib_s16 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32_S32(mlib_f32 *dst, const mlib_s32 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_U8S(mlib_f32 *dst, const mlib_u8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S8S(mlib_f32 *dst, const mlib_s8 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S16S(mlib_f32 *dst, const mlib_s16 *src, mlib_s32 shift, mlib_s32 n); mlib_status mlib_SignalConvertShift_F32S_S32S(mlib_f32 *dst, const mlib_s32 *src, mlib_s32 shift, mlib_s32 n); Each of these functions performs data type convert with shifting. The following equation is used: dst[i] = src[i] * 2**shift See the following table for available variations of this group of data type convert functions. Type [*] F32 F32S U8 Y S8 Y S16 Y S32 Y U8S Y S8S Y S16S Y S32S Y [*] Each row represents a source data type. Each column represents a destination data type. Each of the functions takes the following arguments: dst Destination signal array. src Source signal array. shift Left shifting factor. n Number of samples in the source signal arrays. Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ mlib_SignalConvertShift_U8_S8_Sat(3MLIB), attributes(5) 10 Nov 2004 mlib_SignalConvertShift_F32_U8(3MLIB)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy