Programming :: Bash: Combine Arrays & Delete Duplicates?
May 23, 2011
I would like to combine two arrays and delete duplicates that might occur. I tried to solve it like this:
Code:
combined=( "${results1[@]}" "${results2[@]}" )
printf "${combined[@]}" | sort -n | uniq
Example:
result1 (4 elements):
[Code]....
In my code printf seems to have a problem with elements that have the same letters but a space inbetween. For instance "new foo", "newfoo" are the same for printf
View 5 Replies
ADVERTISEMENT
Nov 20, 2010
I'm writing a bash script to auto run on boot in Tinycore.
This is a watered down version.
Code:
I need it to either not add the time stamp if the awk finds a duplicate or write over the time with the new time if awk finds a duplicate.
BTW this is all pretty much cut-and-paste scripting so please feel free to comment if you know a more elegant way.
View 3 Replies
View Related
Mar 12, 2009
I'm making script for automated compiling of one program which would output builds optimized for many architectures. For clearancy, I do each build in it's own catalogue and list of builds with their respective catalogues would be stored as array. I'm using this guide as reference. It describes making array as naming a variable with additional brackets denoting it's position in array.
In my code, it looks exactly like this:
Code:
mtune[1]="build/mtune/athlon"
mtune[2]="build/mtune/athlon-4"
mtune[3]="build/mtune/athlon-mp"
[code]....
But upon invoking $mtune or any $mtune[x] variable, output is blank, like the variable(s) were never initialized. What am I doing wrong?
View 1 Replies
View Related
Feb 23, 2010
I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.
declare -a arr1
arr1=( $(/some/command) )
Supposing it will eventually (after executing the command) have element values as -
arr1[0]=1234
arr1[1]=5678
arr1[2]=7890
Now, I need to declare another set of arrays, one for each of the element values above - e.g.
declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890
And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -
arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"
arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"
I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.
View 7 Replies
View Related
Aug 2, 2010
I have about 1TB of data to sort out and need a good GUI package to find and safely delete the duplicate files. I am running Ubuntu 10.04 amd_64. Would appriciate any thoughts on how to get it done.
View 8 Replies
View Related
Feb 9, 2010
I have a fallowing CGI script, which does nothing more than prints out the values user inserted:
Code:
If I insert Martin to the name box and 192.168.1.1 to the IP box I get fallowing output:
Quote:
Name is Martin
IP address is 192.168.1.1
As you can see, script above works fine(I host this script in Apache server and use Firefox as a web-client). Now I made a fallowing bash script:
Code:
Which is started like this: ./script.sh Martin 192.168.1.1. Output is user name plus port numbers and descriptions. This bash script works fine as well
How can I combine those two scripts? I would like to insert name and IP to according boxes in Firefox and after clicking Generate button, user name plus list of port numbers and descriptions will appear in Firefox window instead of terminal emulator window
How to link/combine those two scripts to work together as one?
View 2 Replies
View Related
Apr 9, 2011
I would like to delete a single line from a file that contains many lines passing through the same values as the two parameters. Again, I would like to delete a single line and not all those that contain parameters. How can I make bash?
View 14 Replies
View Related
Oct 19, 2010
I have tried a combination of the following lines in .bashrc to try and control duplicates in the bash history file:
export HISTCONTROL=ignoreboth
export HISTCONTROL=erasedups
export HISTCONTROL=ignoredups
[code]....
View 5 Replies
View Related
Dec 8, 2010
I prefer to delete trailing slahes from pathes. Until now I used sed:
Code: $ myPath=/home/ladygaga///
$ echo "$myPath" | sed 's//*$//'
/home/ladygaga I played around to accomplish the same with on-board means of bash without using sed, but for example this line only deletes one trailing slash:
Code: $ myPath=/home/ladygaga///
$ echo ${myPath%/*}
/home/ladygaga// Is there a way to delete trailing slahes with just on-board means of bash?
View 2 Replies
View Related
Jun 2, 2010
Is there a way to compare an array in a while conditions?
I have one array that contains the results of some search and if the script has found all the items, then it should stop, so my idea is to have a while loop � la:
Code:
View 4 Replies
View Related
Sep 30, 2010
I am writing a script to get the multiples of 2 and 3, place them in an 2 arrays, and then show the common integers. So far everything works fine till the comparision. I don't know how to compare them. Here is the code:
Code:
#!/bin/bash
let num1="2"
let num2="3"
[code]...
View 6 Replies
View Related
Aug 23, 2010
I am trying to get PvPGN working... I have installed all the files, the only thing now is that bntrackd wants to use 'logs/bntrackd.log' for it's logfile, but seeing as it's in /usr/sbin, I want it to use /var/log/bntrackd. This is done with 'bntrackd --logfile=/var/log/bntrackd.log' but when I put that in the script it won't process it as a command (instead splitting it and complaining that I don't have --logfile=/var/log/bntrackd.log installed)
/etc/rc.d/pvpgn:
Code:
#!/bin/bash
...
[ -z "$PVPGN_DAEMONS" ] && PVPGN_DAEMONS=(bnetd d2dbs d2cs)
...
for d in ${PVPGN_DAEMONS[@]}; do
[Code]....
View 4 Replies
View Related
Jul 23, 2011
Code:
#!/bin/bash
f1=apple
f2=banana
f3=grape
echo "Enter number 1,2 or 3:" # 3 is entered
read x
choice=${f+$x} # yielding choice=$f3
echo "$choice" # so $choice is, essentially, read as f3, which = grape
grape I am, essentially, trying to combine "f" and the number entered (3, for example) to create "f3", which when echoed as "$choice" will lead to grape!
View 8 Replies
View Related
Apr 3, 2011
how to combine bash scripting with apache.
View 5 Replies
View Related
Mar 27, 2010
I wonder why arrays in the C programming language are pointers to the first element of the array, not the first element of the array itself?
View 14 Replies
View Related
Oct 31, 2010
I am working on a script that allows me to convert an IP address to a country name. I have 2 files. One that has text like: PORT.80 TCP SRC=x.x.x.x and the other is x.x.x.x United States. How can I combine these files so that the file output is PORT.80 TCP SRC=x.x.x.x United States?
View 5 Replies
View Related
Dec 26, 2010
I have a list of about 425 servers that are mostly redundant. I need to weed out the duplicate names so that I have a count of only the unique server hostnames. What is a good command to do this?
View 3 Replies
View Related
Oct 20, 2010
I have a column of datetime entries which I sorted to removed duplicate entries.
I have still lots of entries which are adjacent to each other by 1 second.
How would I go about removing any entries which have an offset of the previous or after entry by 1 second?
Code:
View 5 Replies
View Related
Mar 1, 2010
I have a problem on a program,the problem take a very long time when i try to add two big arrays element by elementI know that matlab make adding vectors more faster than adding element by element but I don't know how!!!do any body knew how matlab make vectors operations more faster than element by element???I want to make my calculation more faster because the program is very big
View 8 Replies
View Related
Nov 3, 2010
I was reading Kernighan Ritchie book chapter 4 which deals with character pointers.I am not able to understand following different type of declarations
Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time";
[code]...
View 1 Replies
View Related
Sep 3, 2009
need to process files within multiple directories and transfer these to a remote server. What I had in mind was to use arrays for this; code pasted below (explains it better):
Code:
#set the arrays
array_A=( fileA* pathtodestA hostA passwordA )
[code]...
View 8 Replies
View Related
May 12, 2010
Code...
how to combine a and b to c
View 8 Replies
View Related
Jun 19, 2010
Does diff not like arrays? How do achieve the following?
Code:
stuart@stuart:~/music transfer$ diff file1.txt file2.txt
1c1
< bonkers_in_phoenix.mp3
[code]....
View 14 Replies
View Related
Jun 16, 2010
I have a Perl script that has two arrays - they are related. I would like to print out the contents into two columns next to each other.
#!/usr/bin/perl
open(PINGFILE, </home/casper/pingdata.txt") or die " can not open file ";
my @totalfile=<PINGFILE>;
foreach $string(@totalfile) {
if ($string =~ m/(^1sping)(?=.*max))/) {
push(usecstring,"$string");
[Code]...
View 2 Replies
View Related
Apr 18, 2011
I am working on a project that needs to use structures and I'm pretty sure string arrays. First I declare my structures and they must be exactly like this.
typedef struct
{
int hour;
[code]....
View 4 Replies
View Related
Apr 10, 2010
I have a little test program consisting of a NASM source file and a C source file.How do I turn them into a single program?
Code:
section .data
msg db 'Hello, World!', 10
[code]....
View 14 Replies
View Related
Jul 12, 2009
I'm trying to figure how to create an small array of 3x3 arrays such I can do
Code:
SUM1(i) = SUM1(i) + SUM2
where i goes from 1 to 8 and SUM2 is a 3x3 array.
View 2 Replies
View Related
Oct 19, 2010
a project using bluetooth to send data byte by byte to external devices buti'm not familiar using arrays to read file from another location before sending the data.If you could,do correct my codes.Here's my code,
void loop(){
char Msg[]={"Hello"};
char *start;
[code]...
View 2 Replies
View Related
Dec 10, 2008
I have something like this:
$arr_hash{'produce'}{'veggies'}[0] = Broccoli
$arr_hash{'produce'}{'veggies'}[1] = Cauliflower
$arr_hash{'produce'}{'veggies'}[2] = Carrots
[code]...
View 2 Replies
View Related
Feb 18, 2010
I'm trying to figure out how to code for this specific type of instance - I want to use a hash and have the key be a reference to an array, and not use the key in the standard way of it being a scalar. Basically, I have a large output that I need to process line by line, and rather have access to it as an array than a big block in a scalar. For the big block hash as a scalar I would do -
Code:
foreach $CONTROLLER (<CONTROLLER_LIST>) {
$ALL_DISKS{$CONTROLLER} = `ssh -n <commands>`;
}
Now I know I could take the scalar and split it to another array after the fact like -
Code:
@TEMP_HOLD = split (/s+/,$ALL_DISKS{$CONTROLLER});
How would I code it that I would have access to the key information as an array and not a scalar? I know it needs to be a pointer and we're going to have -> in there somewhere, but not sure how to approach it. Some of the documentaiton I've been reading about referencing I've found a little confusing so far, and trying to figure out how to use them in context of what I'm working on.
View 1 Replies
View Related