Yes, it looks like some of your problem is your loop structure. The while loop is capturing the last record from your text file and comparing that against the file name component. I would guess that you want the filename, or some part of the filename, compared to the information in each line of the text file until you find a match.
It's not efficient, but the logic below might do what you need.
I couldn't tell from your code whether the filenames had the suffix tacked onto the end (picture.jpgxxxx) or picture.xxxx.jpg. The ls command implies the latter, but you seem to be stripping off xxxx as the trailing 4 characters. You might be getting tripped up with this too. If you post a sample of filenames and a sample of your text file, it'd make giving suggestions a bit easier.
Nitpicking now.... the statement
can be written more simply:
This is easier to read, and depending on the shell it more efficient. There might also be ways to make sussing the field data from the text file more efficient; using external processes like 'cut' introduce overhead that can eat your lunch as far as performance is concerned.
I have a file that lists data about a system. It has a part that can look like:
the errors I'm looking for with other errors:
Alerts
Password Incorrect
Login Error
Another Error
Another Error 2
Other Info
or, just the errors I need to parse for:
Alerts
Password Incorrect
... (9 Replies)
For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)?
For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
i have a variable MYHOST that has my host name.depending on the host i have an array like A_<hostname>.Everytime i need to append the hostname to A_ to get the array.but in the shell script i am nt able to access the members of that array.
code of what i hav done:
export temp=A_$MYHOST
for... (15 Replies)
Hi there,
I have included an external properties file into my BASH script via the 'source' command.
I am attempting to dynamically assign a variable in the BASH script, that references the variable name within the external properties file i.e.
#!/bin/bash
pth=${0%/*}
source... (3 Replies)
Hello All,
I am having this issue...where I am actually having hard time understanding the problem:
The code is as follows:
#include<iostream.h>
void fxn(char*** var)
{
int i =4;
*var = (char**)malloc(i*sizeof(char*));
for(int j =0; j<4; j++)
{
*var = "name";
cout<<*var;... (6 Replies)
Here is the question...
Create a new script, sub2, taking three parameters...
1.) the string to be replaced
2.) the string with which to replace it
3.) the name of the file in which to make the substitution
...that treats the string to be replaced as plain text instead of as a regular... (1 Reply)
Dear all,
I believe this is a Bash basic question... I am bit ashamed for asking actually...
I want to create a Bash script that compares 2 different folders:
1) work_folder
and
2) work_folder.git
#!/bin/bash
FOLDER_NAME=`pwd | awk -F/ '{ print $NF }' | awk -F. '{ print $1 }'`
... (6 Replies)
Discussion started by: freddie50
6 Replies
LEARN ABOUT CENTOS
rand_load_file
RAND_load_file(3) OpenSSL RAND_load_file(3)NAME
RAND_load_file, RAND_write_file, RAND_file_name - PRNG seed file
SYNOPSIS
#include <openssl/rand.h>
const char *RAND_file_name(char *buf, size_t num);
int RAND_load_file(const char *filename, long max_bytes);
int RAND_write_file(const char *filename);
DESCRIPTION
RAND_file_name() generates a default path for the random seed file. buf points to a buffer of size num in which to store the filename. The
seed file is $RANDFILE if that environment variable is set, $HOME/.rnd otherwise. If $HOME is not set either, or num is too small for the
path name, an error occurs.
RAND_load_file() reads a number of bytes from file filename and adds them to the PRNG. If max_bytes is non-negative, up to to max_bytes are
read; starting with OpenSSL 0.9.5, if max_bytes is -1, the complete file is read.
RAND_write_file() writes a number of random bytes (currently 1024) to file filename which can be used to initialize the PRNG by calling
RAND_load_file() in a later session.
RETURN VALUES
RAND_load_file() returns the number of bytes read.
RAND_write_file() returns the number of bytes written, and -1 if the bytes written were generated without appropriate seed.
RAND_file_name() returns a pointer to buf on success, and NULL on error.
SEE ALSO rand(3), RAND_add(3), RAND_cleanup(3)HISTORY
RAND_load_file(), RAND_write_file() and RAND_file_name() are available in all versions of SSLeay and OpenSSL.
1.0.1e 2013-02-11 RAND_load_file(3)