Thursday, May 2, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 2320  / 2 Years ago, fri, december 17, 2021, 2:51:50

I would like to do the following in a bash script:




  1. read some filenames out of an file with filenames

  2. set a variable input path

  3. concat 1. and 2.

  4. use 3. in sql-statement



Here my code:



 #!/bin/bash
INPath="/home/bono/RD/BV-OUT/"

while
read line
do
RD="$line"
RDFile="$INPath$RD"

echo -e $RDFile

###MYSQLs:
mysql -u root -D RD --local-infile << EOF
LOAD DATA LOCAL INFILE '$RDFile'
INTO TABLE bv_tmp_all FIELDS TERMINATED BY ';' LINES TERMINATED BY '
';
EOF
##### EOSQL

done < /home/bono/RD/BV-OUT/allto468


The echo shows the right path and filenamen but mysql always says:



not found (Errcode: 2 - File or Directory not found)  


I've tried different ways to concate the two strings but none worked :(



The following code works with mysql (without the concate) but it is not what I need:



 #!/bin/bash

while
read line
do

RDFile="/home/bono/RD/BV-OUT/468-R11"

echo -e $RDFile

###MYSQLs:
mysql -u root -D RD --local-infile << EOF
LOAD DATA LOCAL INFILE '$RDFile'
INTO TABLE bv_tmp_all FIELDS TERMINATED BY ';' LINES TERMINATED BY '
';
EOF
##### EOSQL

done < /home/bono/RD/BV-OUT/allto468


What is wrong with the concate?


More From » command-line

 Answers
7

If the allto468 itself has
line endings, then $line will look like 468-R11
, and that file is surely not found.



Solutions




  1. run dos2unix on the allto468 file to fix the issue once,

  2. change the done line to



    done < <(sed 's/
    $//' /home/bono/RD/BV-OUT/allto468)


[#27096] Saturday, December 18, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
barted

Total Points: 424
Total Questions: 103
Total Answers: 101

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
barted questions
;