Sponsored Content
Top Forums Shell Programming and Scripting Split list of files into an array and pass to function Post 302931539 by sea on Tuesday 13th of January 2015 03:55:34 PM
Old 01-13-2015
Ok, not the nicest, but it seems to work:
Code:
#!/bin/bash
ARRAY_ORGINAL=("${@}")
declare -a ARRAY1 ARRAY2 ARRAY3 ARRAY4
TOTAL=${#ARRAY_ORGINAL[@]}
MAX=$((  $TOTAL / 4 ))

count=0
ARRAY1=( ${ARRAY_ORGINAL[@]:$count:$MAX} )
n=0
while [[ $n -le $MAX ]]
do	#set -x
	unset ARRAY_ORGINAL[$n]
	n=$(($n+1))
done

count=$(($count+$MAX))
ARRAY2=( ${ARRAY_ORGINAL[@]:$count:$MAX} )
n=0
while [[ $n -le $MAX ]]
do	unset ARRAY_ORGINAL[$n]
	n=$(($n+1))
done

count=$(($count+$MAX))
ARRAY3=( ${ARRAY_ORGINAL[@]:$count:$MAX} )
n=0
while [[ $n -le $MAX ]]
do	unset ARRAY_ORGINAL[$n]
	n=$(($n+1))
done

count=$(($count+$MAX))
ARRAY4=( ${ARRAY_ORGINAL[@]:$count:$MAX} )
n=0
while [[ $n -le $MAX ]]
do	unset ARRAY_ORGINAL[$n]
	n=$(($n+1))
done

echo "1 : ${ARRAY1[@]}"
echo "2 : ${ARRAY2[@]}"
echo "3 : ${ARRAY3[@]}"
echo "4 : ${ARRAY4[@]}"

Code:
sh test.sh  a b c d e f g h i j k l
1 : a b c
2 : e f g
3 : g h i
4 : j k l

Left overs (as in, provided argument list is not 'equaly' dividable by 4) are not handled here.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can we pass array with call by value in function

I want to pass an array in my function, And my function will be changing the elements of the array in the fuction, but it should not affect the values in my array variable of main function (1 Reply)
Discussion started by: ranjithpr
1 Replies

2. Shell Programming and Scripting

Array split function & hashes

Hi, If this is the array that is being returned to me: How would I get the values for each of the 3 records? This works for 1 Record: foreach $item (@results) { ($id, $id2, $name, $date, $email) = split(/\|/, $item, 5); print "$name<br>"; } (2 Replies)
Discussion started by: novera
2 Replies

3. Shell Programming and Scripting

How to pass an array from SHELL to C function

Hi, I have an output generated from a shell script like; 0x41,0xF2,0x59,0xDD,0x86,0xD3,0xEF,0x61,0xF2 How can I pass this value to the C function, as below; int main(int argc, char *argv) { unsigned char hellopdu={above value}; } Regards Elthox (1 Reply)
Discussion started by: elthox
1 Replies

4. Shell Programming and Scripting

Find and split the list of files with suffiz of seg**

Hi,. I am writing a script to get the new files and split them. Requirement Find the new files under the path "/wload/scmp/app/data/OAS" (There are 5 sub folders). Gunzip the files which are having .gz suffix. Put the list of files in the filename in the format... (0 Replies)
Discussion started by: Satish Shettar
0 Replies

5. Shell Programming and Scripting

Split the file and access that files through array and loop

Hi All, the below is my requirement.. i need to split the file based on line and put that files in a array and need to access that files through loop finally i should send the files through mail.. how can we achieve this ..I am new to shell script please guide me.. I am using KSH.. ... (11 Replies)
Discussion started by: kalidoss
11 Replies

6. Shell Programming and Scripting

How to pass an array to a function in shell script.?

hi, I have a array say SAP_ARRAY="s1.txt" SAP_ARRAY="s2.txt" how can i pass this full array to a function. here is the sample code i am using.. CHECK_NO_FILES() { FARRAY=$1 echo "FARRAY = $FARRAY" echo "FARRAY = $FARRAY" ............... (5 Replies)
Discussion started by: Little
5 Replies

7. Shell Programming and Scripting

Question about sorting -- how to pass an array to a function

Hi, guys I just wanted to sort the elements of an array ascendingly. I know the following code does work well: array=(13 435 8 23 100) for i in {0..4} do j=$((i+1)) while ] do if } -le ${array} ]] then : else min=${array} ${array}=${array} ${array}=$min fi... (5 Replies)
Discussion started by: franksunnn
5 Replies

8. Shell Programming and Scripting

Pass array to a function and display the array

Hi All I have multiple arrays like below. set -A val1 1 2 4 5 set -A val2 a b c d . . . Now i would like to pass the individual arrays one by one to a function and display/ do some action. Note : I am using ksh Can you please advise any solution... Thanks in advance. (7 Replies)
Discussion started by: Girish19
7 Replies

9. Shell Programming and Scripting

Pass an array to awk to sequentially look for a list of items in a file

Hello, I need to collect some statistical results from a series of files that are being generated by other software. The files are tab delimited. There are 4 different sets of statistics in each file where there is a line indicating what the statistic set is, followed by 5 lines of values. It... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

10. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies
dpkg-split(1)							  dpkg utilities						     dpkg-split(1)

NAME
dpkg-split - Debian package archive split/join tool SYNOPSIS
dpkg-split [option...] command DESCRIPTION
dpkg-split splits Debian binary package files into smaller parts and reassembles them again, to support the storage of large package files on small media such as floppy disks. It can be operated manually using the --split, --join and --info options. It also has an automatic mode, invoked using the --auto option, where it maintains a queue of parts seen but not yet reassembled and reassembles a package file when it has seen all of its parts. The --listq and --discard options allow the management of the queue. All splitting, joining and queueing operations produce informative messages on standard output; these may safely be ignored. COMMANDS
-s, --split complete-archive [prefix] Splits a single Debian binary package into several parts. The parts are named prefix.NofM.deb where N is the part number, starting at 1, and M is the total number of parts (both in decimal). If no prefix is supplied then the complete-archive filename is taken, including directory, with any trailing .deb removed. -j, --join part... Joins the parts of a package file together, reassembling the original file as it was before it was split. The part files given as arguments must be all the parts of exactly the same original binary file. Each part must occur exactly once in the argument list, though the parts to not need to be listed in order. The parts must of course all have been generated with the same part size specified at split time, which means that they must usually have been generated by the same invocation of dpkg-split --split. The parts' filenames are not significant for the reassembly process. By default the output file is called package_version_arch.deb. -I, --info part... Prints information, in a human-readable format, about the part file(s) specified. Arguments which are not binary package parts pro- duce a message saying so instead (but still on standard output). -a, --auto -o complete-output part Automatically queue parts and reassemble a package if possible. The part specified is examined, and compared with other parts of the same package (if any) in the queue of packages file parts. If all parts of the package file of which part is a part are available then the package is reassembled and written to complete-out- put (which should not usually already exist, though this is not an error). If not then the part is copied into the queue and complete-output is not created. If part is not a split binary package part then dpkg-split will exit with status 1; if some other trouble occurs then it will exit with status 2. The --output or -o option must be supplied when using --auto. (If this were not mandatory the calling program would not know what output file to expect.) -l, --listq Lists the contents of the queue of packages to be reassembled. For each package file of which parts are in the queue the output gives the name of the package, the parts in the queue, and the total number of bytes stored in the queue. -d, --discard [package...] This discards parts from the queue of those waiting for the remaining parts of their packages. If no package is specified then the queue is cleared completely; if any are specified then only parts of the relevant package(s) are deleted. -?, --help Show the usage message and exit. --version Show the version and exit. OPTIONS
--depotdir directory Specifies an alternative directory for the queue of parts awaiting automatic reassembly. The default is /var/lib/dpkg. -S, --partsize kibibytes Specifies the maximum part size when splitting, in kibibytes (1024 bytes). The default is 450 KiB. -o, --output complete-output Specifies the output file name for a reassembly. This overrides the default for a manual reassembly (--join) and is mandatory for an automatic queue-or-reassemble (--auto). -Q, --npquiet When doing automatic queue-or-reassembly dpkg-split usually prints a message if it is given a part that is not a binary package part. This option suppresses this message, to allow programs such as dpkg to cope with both split and unsplit packages without pro- ducing spurious messages. --msdos Forces the output filenames generated by --split to be msdos-compatible. This mangles the prefix - either the default derived from the input filename or the one supplied as an argument: alphanumerics are lowercased, plus signs are replaced by x's and all other characters are discarded. The result is then truncated as much as is necessary, and filenames of the form prefixNofM.deb are generated. EXIT STATUS
0 The requested split, merge, or other command succeeded. --info commands count as successful even if the files are not binary pack- age parts. 1 Only occurs with --auto and indicates that the part file was not a binary package part. 2 Some kind of trouble happened, such as a system call failure, a file that looked like a package part file but was corrupted, a usage error or some other problem. BUGS
Full details of the packages in the queue are impossible to get without digging into the queue directory yourself. There is no easy way to test whether a file that may be a binary package part is one. FILES
/var/lib/dpkg/parts The default queue directory for part files awaiting automatic reassembly. The filenames used in this directory are in a format internal to dpkg-split and are unlikely to be useful to other programs, and in any case the filename format should not be relied upon. SEE ALSO
deb(5), deb-control(5), dpkg-deb(1), dpkg(1). Debian Project 2011-07-04 dpkg-split(1)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy