I know I should be able to see a way of doing this easily, but my brain just won't engage.
I have a script working on an embedded device that checks to see if an item is in a blacklist before performing some actions.
At the moment the code reads thus....
The items in BLACKLIST.txt are single words separated by a \n
I'm trying to replace the BLACKLIST.txt file by putting the list directly into the script as a variable (INBLACKLIST) at the top of the file with each item separated by a space and then using tr " " "\n" to put them on separate lines. This is to try to make the script as portable as possible without relying on any outside dependencies.
What I was hoping to do in the new code was
This isn't working, the first value gets passed to BLACKLIST but it looks like the while read isn't working.
I'm sure there's a better way to do this but to be honest I'm so tired my brain has frozen up.......can anyone suggest another way.
Thanks in advance and I'm going to put on a fresh pot of coffee in the hope someone out there can help me!!
Last edited by zaxxon; 09-10-2010 at 05:13 AM..
Reason: subject change
Klashxx , that's still piping from a file surely? It doesn't work I'm afraid.
Franklin.
I tried with the variables on INBLACKLIST being either space separated or newline separated and it doesn't work either way, this could be because it's an ASH rather then BASH shell? (embedded device using busybox).
either way the `for BLACKLIST in "$INBLACKLIST"` is reading in all the values in $INBLACKLIST (either on one line or multiple lines as separated).
I have put an echo "$BLACKLIST" immediately after the `for BLACKLIST....` to check.
I tried with the variables on INBLACKLIST being either space separated or newline separated and it doesn't work either way, this could be because it's an ASH rather then BASH shell? (embedded device using busybox).
either way the `for BLACKLIST in "$INBLACKLIST"` is reading in all the values in $INBLACKLIST (either on one line or multiple lines as separated).
I have put an echo "$BLACKLIST" immediately after the `for BLACKLIST....` to check.
Any other ideas please chaps?
Oops, try it without the double quotes around $INBLACKLIST in the loop:
Hello All,
I have two files with me file1.txt and file2.txt
file1.txt has:
333
222
111
file2.txt has
ccc
bbb
aaa
ccc is related to 333 only, bbb is related to 222 only and aaa is related to 111 only.
I have to get the values from each of the file and pass them in the URL... (3 Replies)
Hello,
I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below:
# cat /tmp/passwd_sample
CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash
HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash... (4 Replies)
Hi,
I am writing in a file through cat command. This file will contain the path of file along with filename. e.g. /home/user/folder1/folder2/filename.txt
There might be very large number of this path in same file like say 140
when I try to run while command:
while read -r file
do
//command... (8 Replies)
Hi,
I am on HP-UX and K shell.
When I am using while/for loop for reading a file. It is working fine but not reading tabs:
Suppose, if the line is: ; ;COMP; ; ; ;
then loop is reading as
; ;COMP; ;... (5 Replies)
Hello All,
i am a newbie and need some help when reading a csv file in a bourne shell script. I want to read 10 lines, then wait for a minute and then do a reading of another 10 lines and so on in the same way. I want to do this till the end of file.
Any inputs are appreciated
... (3 Replies)
I have written a script to read the file line by line.
It is reading and printing the lines.
But it is coming out of loop before reading last line.
So I am not able to print last line.
How do I solve it. (6 Replies)
Hi,
I am building a script to grep for a string in all the files from a folder and display the results.
I am reading the files one by one by placing the names in other file using while loop
my code is as below
while read inp
do
chk=`grep -c "$str" $pth/$inp`
... (2 Replies)
Greeting,
The following script completes after reading only one record from the input file that contains many records. I commented out the "ssh" and get what I expect, an echo of all the records in the input.txt file. Is ssh killing the file handle?
On the box "uname -a" gives "SunOS... (2 Replies)
I am not able to read inside a while though i get the message "inside read" the cursor doesnt prompt from the console
cat file | while read ln_new_engine_dirs
do
echo "inside $ln_new_engine_dirs"
if
then
read nn
echo "inside read"
fi
done
Thanks in advance (3 Replies)
i have a teat file having data like
one 12/3
two 23/09
three 12/12
now from another script i want to read one line at a time ,cut field one and two in two separate variable ,compare field1 with another variable
but outside the loop .If i found a match i want to take from user the value... (2 Replies)