LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2009, 08:10 PM   #1
MinnesotaDrifter
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 0
Bash array question


*Feel free to skip to the my second post as this is just a broad overview of my goals.

Okay, I figured it out... I'll post that later.

Last edited by MinnesotaDrifter; 01-21-2009 at 03:14 PM.
 
Old 01-19-2009, 12:16 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Please post your code so far...
 
Old 01-19-2009, 04:06 AM   #3
MinnesotaDrifter
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Sure thing, here's the relevant portion...

Like I was saying, the only thing that I need help with is portion offset by the ################ symbols. I am looking for something that will allow me to compare the strings in the bg array to the strings in the temp array and delete any matching string from the temp array.

Hopefully, this isn't too confusing.


Code:
#!/bin/bash

#part1 input data location and output location / open bg.list

echo "Input data location"
read input
echo "Input output location"
read output
echo "Opening bg.list...."

declare -a bg
#Open bg.list for reading to bg
exec 10<bg.list   
let count=0  

while read LINE <&10; do

    bg[$count]=$LINE
    ((count++))       #for testing purposes
done

echo ${bg[@]}
# close file
exec 10>&-

#part2 aor numbers and dates 
  
cd $input
array=(`ls`)
length=${#array[@]}

i=0
while [ $i -lt $length ]; do
temparr=`ls ${array[$i]}`
  
#####################################################################
#here i try to see if any elements of the bg array match those in the 
#temp array
echo ${temparr[@]#${bg[@]}} #this is what doesn't work
# but i'm guessing something similiar might?
#####################################################################

array2[$i]=${temparr[@]} #should only be 1 if everything works correctly
array2[$i]=${array2[$i]/#r/} #remove r's (see first post if you care)

echo "1st: ${array[$i]}"
echo "2nd: ${array2[$i]}" #currently, not what I'd like to see
let i++
done
 
Old 01-21-2009, 01:11 AM   #4
MinnesotaDrifter
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Okay, so I've given up on something simple like I was thinking before and am trying to do this with another while loop. I was thinking something like the following, but I wasn't getting it to work, any insights?

Remember, I am just try to compare an array of 7 or 8 values with an array of 2, and remove the one from the array of 2 that matches.

The following code is an example of what I'm trying to get to work. But the "echo ${temparr[0]#${bg[i]}}" doesn't remove the occurance of ${bg[i]}} from the temporary array temparr at [0].

Code:
#! /bin/bash
bg[0]=1
bg[1]=2
bg[2]=3
bg[3]=4
length=${#bg[@]}
echo $length
temparr[0]=1
temparr[1]=7
i=0
while [ $i -lt $length ]
do
echo ${bg[i]} ${temparr[0]} ${temparr[1]}

if [ ${temparr[0]} -eq ${bg[i]} ];
then echo ${temparr[0]#${bg[i]}}
fi
if [ ${temparr[1]} -eq ${bg[i]} ];
then echo ${temparr[1]#${bg[i]}}
fi

i=$(( $i + 1 ))
done

echo "bg:" ${bg[@]}
echo "temparr:" ${temparr[@]}

Last edited by MinnesotaDrifter; 01-21-2009 at 10:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Variable Array, Trying to add another value into the array helptonewbie Linux - Newbie 6 03-03-2009 12:18 AM
bash array question dazdaz Programming 8 11-21-2008 12:40 PM
array in bash ramesh_manu Linux - Newbie 1 02-24-2007 12:19 PM
Bash array question krock923 Programming 3 06-22-2006 12:39 PM
Array Help in BASH! ?*%$ johnnybhoy67 Linux - Software 2 02-22-2006 11:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration