Sponsored Content
Full Discussion: Using array in script?
Top Forums Shell Programming and Scripting Using array in script? Post 302765399 by emily on Saturday 2nd of February 2013 07:37:27 AM
Old 02-02-2013
Hi Don Cragun,
I appreciate your reply and the time you spend on that piece of code.
I completely agree with you and ctsgnb that code is far from optimization.

Being novice with shell scripting, I was happy with the idea that I could make working script which looks nasty but does my task pretty well. And the sole reason to post the question here was try to optimize it. That also make me learn more of shell scripting.

Now, Let me explain you the task of this piece of the script.
I have several of the files kept at some locations like
Code:
$ls /path/path_goesTo/A/
vgtree_132_1_vsd.root  vgtree_182_1_asq.root  vgtree_231_1_FWO.root  vgtree_281_1_RV7.root  vgtree_39_1_HCC.root   vgtree_89_1_oaM.root
vgtree_133_1_lDx.root  vgtree_183_1_1lF.root  vgtree_23_1_q4e.root   vgtree_28_1_OkE.root   vgtree_40_1_ROj.root   vgtree_90_1_nfF.root
vgtree_134_1_rtQ.root  vgtree_184_1_JDe.root  vgtree_232_1_rNt.root  vgtree_282_1_sK6.root  vgtree_41_1_1JA.root   vgtree_91_1_9r8.root
vgtree_135_1_U24.root  vgtree_185_1_S7u.root  vgtree_233_1_KrH.root  vgtree_283_1_3Wj.root  vgtree_4_1_YrR.root    vgtree_9_1_NME.root
vgtree_136_1_TrA.root  vgtree_186_1_HwX.root  vgtree_234_1_3pj.root  vgtree_284_1_N3Z.root  vgtree_42_1_DcY.root   vgtree_92_1_JQY.root
vgtree_137_1_yVj.root  vgtree_187_1_cda.root  vgtree_235_1_XrJ.root  vgtree_285_1_z8g.root  vgtree_43_1_msk.root   vgtree_93_1_oOe.root
vgtree_138_1_zOd.root  vgtree_188_1_N2U.root  vgtree_236_1_wpb.root  vgtree_286_1_CLY.root  vgtree_44_1_yDV.root   vgtree_94_1_1YG.root
vgtree_139_1_Gmf.root  vgtree_189_1_ohb.root  vgtree_237_1_PF2.root  vgtree_287_1_3oO.root  vgtree_45_1_ZWL.root   vgtree_95_1_SQx.root

And my purpose is to copy them in one common file named $FileName. Important is to make sure that if there is any repeating of files than only the file with the bigger size should be kept.

Repeating would implies, in the given example the deciding critera is to match the no '187' and if there are three different files, go for copying the file name vgtree_187_1_cda.root
Code:
-rw-r--r-- 1 pooja04 us_cms 38939100 Dec 19 21:38 vgtree_187_1_cda.root
-rw-r--r-- 1 pooja04 us_cms 8900 Dec 19 21:38 vgtree_187_2_jdy.root
-rw-r--r-- 1 pooja04 us_cms 939100 Dec 19 21:38 vgtree_187_3_chj.root

Following this criteria I want a final file $DataFile with the content as:
Code:
/path/path_goesTo/A/vgtree_95_1_SQx.root
/path/path_goesTo/A/vgtree_96_1_TGx.root
/path/path_goesTo/A/vgtree_97_2_YKx.root
/path/path_goesTo/A/vgtree_98_1_RKx.root


And the following as I explained for single $PATH would infect be repeated for several of PATH and with millions of root files.

I hope, I could clear as what I wanted to do.

Thanks a lot
pooja
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix script array

Unix shell script; How do I create an array and dynamically populate it with values? How do I retrieve from the array? (4 Replies)
Discussion started by: leemjesse
4 Replies

2. Shell Programming and Scripting

Please Correct this Array Script

Here is the script. I am not able to increment and Print echo "2=" ${arr} (Bold line) Can someone please help me correct it? I am thinking there is some escape sequence error. Just started learning scripts ... Thanks #!/bin/ksh set -A arr a1 a2 a3 a4 # START Server1=gmi ... (6 Replies)
Discussion started by: psreddy1234
6 Replies

3. Shell Programming and Scripting

KSH script not looping through array

Hi All, I'm trying to get a script to loop through an array. The array is basically a list of .zip files. I'd like the script to loop through and unzip the zip files contained in the zip file list. When I run the script, it unzip the first zip file correctly, and then stops Any thoughts? Here's... (2 Replies)
Discussion started by: kelldan
2 Replies

4. Shell Programming and Scripting

How to export an array to perl script?

hi all...... i want to use an array ,declared in bash, in embedded perl script. is there any way to export whole array so that i can use it '$ENV{}' or something.. thanx in advance!! regards, prayush (1 Reply)
Discussion started by: tprayush
1 Replies

5. Emergency UNIX and Linux Support

Problem with Array in Script

Below is my script. This script is getting an error code such as this one. fileListener.bat: entityArray=craig.uss@pnc.com: not found craig.uss@pnc.com fileListener.bat: entityArray=duns_noncusts.txt: not found duns_noncusts.txt fileListener.bat: entityArray=duns_misc.cpy: not found... (4 Replies)
Discussion started by: mkjp
4 Replies

6. Shell Programming and Scripting

A typical array script

Hi All, I need to store the output of "find ." to an array one by one. Output of find . in my case will look like :- . ./one ./one/a ./one/b ./one/c ./two So my first array element should be "/one" and second one "/one/a" (need to remove "." from the output as well). Then I need to... (11 Replies)
Discussion started by: Renjesh
11 Replies

7. Shell Programming and Scripting

sendEmail: Script and Array

I have a script that send email using sendEmail (CentOS shell) script is: sendEmail -vvv -u "TestCompany, Inc.: USB Added" -f user@domain.com -t To@domain.com -s ASPMX.L.GOOGLE.com -m "USB Activity" -o tls=aut o username=user3@domain.com password=password So far this works fine. Now i... (5 Replies)
Discussion started by: kashif.live
5 Replies

8. Shell Programming and Scripting

Array in shell script

Hi, check=("/usr/local/bin/chk_nag | awk -F":" '{print $1}'" "/usr/local/bin/chk_kas | awk -F":" '{print $1}'" "/usr/local/bin/chk_was | awk -F":" '{print $1}'" ) for i in "${check}"; do echo $i; done when I run this. It says Syntax error: "(" unexpected Please advise. (5 Replies)
Discussion started by: ashokvpp
5 Replies

9. UNIX for Advanced & Expert Users

Help in perl script Array.

hi Team, i need a help in perl , i need to get values(10 rows +) from perl GUI and insert those values into oracle table. am trying to achive this in Perl array, can you please help me on this. thanks senthil (1 Reply)
Discussion started by: senkerth
1 Replies

10. Shell Programming and Scripting

Need Shell Script for Array

Hi all, I have an input file like below (a comma seperated file) 345,12,10 400,11,8 328,1,3 I need to get the output as below ... record 345 sum is 12 record 400 sum is 10 record 328 sum is 1 record 345 count is 10 record 400 count is 8 record 328 count... (15 Replies)
Discussion started by: hemanthsaikumar
15 Replies
DH_INSTALLINIT(1)						     Debhelper							 DH_INSTALLINIT(1)

NAME
dh_installinit - install init scripts and/or upstart jobs into package build directories SYNOPSIS
dh_installinit [debhelperoptions] [--name=name] [-n] [-R] [-r] [-d] [--params] DESCRIPTION
dh_installinit is a debhelper program that is responsible for installing init scripts with associated defaults files, as well as upstart job files into package build directories. It also automatically generates the postinst and postrm and prerm commands needed to set up the symlinks in /etc/rc*.d/ to start and stop the init scripts. FILES
debian/package.init If this exists, it is installed into etc/init.d/package in the package build directory. debian/package.default If this exists, it is installed into etc/default/package in the package build directory. debian/package.upstart If this exists, it is installed into etc/init/package.conf in the package build directory. OPTIONS
-n, --noscripts Do not modify postinst/postrm/prerm scripts. -o, --onlyscripts Only modify postinst/postrm/prerm scripts, do not actually install any init script, default files, or upstart job. May be useful if the init script or upstart job is shipped and/or installed by upstream in a way that doesn't make it easy to let dh_installinit find it. -R, --restart-after-upgrade Do not stop the init script until after the package upgrade has been completed. This is different than the default behavior, which stops the script in the prerm, and starts it again in the postinst. This can be useful for daemons that should not have a possibly long downtime during upgrade. But you should make sure that the daemon will not get confused by the package being upgraded while it's running before using this option. -r, --no-restart-on-upgrade Do not stop init script on upgrade. --no-start Do not start the init script on install or upgrade, or stop it on removal. Only call update-rc.d. Useful for rcS scripts. -d, --remove-d Remove trailing d from the name of the package, and use the result for the filename the upstart job file is installed as in etc/init/ , and for the filename the init script is installed as in etc/init.d and the default file is installed as in etc/default/ . This may be useful for daemons with names ending in d. (Note: this takes precedence over the --init-script parameter described below.) -uparams --update-rcd-params=params -- params Pass params to update-rc.d(8). If not specified, defaults will be passed to update-rc.d(8). --name=name Install the init script (and default file) as well as upstart job file using the filename name instead of the default filename, which is the package name. When this parameter is used, dh_installinit looks for and installs files named debian/package.name.init, debian/package.name.default and debian/package.name.upstart instead of the usual debian/package.init, debian/package.default and debian/package.upstart. --init-script=scriptname Use scriptname as the filename the init script is installed as in etc/init.d/ (and also use it as the filename for the defaults file, if it is installed). If you use this parameter, dh_installinit will look to see if a file in the debian/ directory exists that looks like package.scriptname and if so will install it as the init script in preference to the files it normally installs. This parameter is deprecated, use the --name parameter instead. This parameter is incompatible with the use of upstart jobs. --error-handler=function Call the named shell function if running the init script fails. The function should be provided in the prerm and postinst scripts, before the #DEBHELPER# token. NOTES
Note that this command is not idempotent. dh_prep(1) should be called between invocations of this command. Otherwise, it may cause multiple instances of the same text to be added to maintainer scripts. SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHORS
Joey Hess <joeyh@debian.org> Steve Langasek <steve.langasek@canonical.com> 9.20120909 2012-04-10 DH_INSTALLINIT(1)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy