Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Have a file full of scanned directories so trying to read it into an array but always get an error saying
This is a directory not a file. Thought the code for reading lines from a file was generic but guess not! So what code is needed to read each line in the file generically or as directories?
Without an actual example of the file contents, the script code used to read it into an array and the exact error being produced, the question is really without meaning.
Please provide enough actual detail to allow us to understand the question and try to provide a useful answer without the need to guess about every piece of the puzzle.
read and readarray process a text file.
A directory is not a text file, not even a binary file (though there are some similarities).
In bash use a for loop:
Code:
for fn in * .*
do
[ -e "fn" ] || continue
echo "do sth with $fn"
done
The .* lists the hidden files. (Or use "shopt -s dotglob" to include hidden files in the * )
You can prefix a dirpath: $dir/* $dir/.*
And you can filter: $dir/*.txt $dir/*.php (or $dir/*.{txt,php} )
Last edited by MadeInGermany; 07-08-2023 at 01:19 AM.
OK! Well the file am reading is one created by KFind and dumped into a .txt file so nothing but directories in this file. So no need to even think any kind of ls cmd. My code reading this is:
Quote:
while IFS=read -r line; do
if [[ -n ”$line" && "$line" == "'/3T'" ]]; then
$oray+="$line"
fi
done < $srcfil
I'm thinking the IFS means the line must qualify as a file, which a directory will never do. Am I right?
What does that mean? You have directories in a file. You have file paths and directory paths listed in a file.txt?
Code:
txt="
/usr/lib/libargon2.so.1
/usr/lib/libasm-0.189.so
/usr/lib/libassuan.so.0.8.5
/usr/lib/vdpau
/usr/lib/udev
"
while read line; do
if [ -d "$line" ]; then
echo ""$line" is a directory path."
fi
if [ -f "$line" ]; then
echo ""$line" is a regular file path"
fi
done <<< "$txt"
/usr/lib/libargon2.so.1 is a regular file path
/usr/lib/libasm-0.189.so is a regular file path
/usr/lib/libassuan.so.0.8.5 is a regular file path
/usr/lib/vdpau is a directory path.
/usr/lib/udev is a directory path.
Got a novel thought so ran a KFind on all .sh files looking for the word "mysql" and found serveral examples.
Now working on editing this, but per my PHP Config post not able to see results in PPHPmyAdmin, but have MySQL Workbench installed so will have to find results there.
Will let you know where I get with this, hopefully over the weekend.
You can always use the mysql command line client to insert values.
mysql_query="insert into table x (column1...) values(data1...);"
mysql -u username -e "$mysql_query"
If the table is created with an unique index on the value you will not have any duplicate rows. Instead of an array you can create a CSV file and import that into mysql.
You can always use the mysql command line client to insert values.
mysql_query="insert into table x (column1...) values(data1...);"
mysql -u username -e "$mysql_query"
If the table is created with an unique index on the value you will not have any duplicate rows. Instead of an array you can create a CSV file and import that into mysql.
michaelk,
The insert is not the problem but getting a return or error from the select query looking for duplicates is the issue!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.