0

It can not generate two temp-files! Why not? Please help!! The input-file has two columns for the file names.

But it fails to copy the TWO-files "fn1", "fn2" into "Data1.dat", "Data2.dat"

What is wrong here??

#!/bin/bash

FF1=$1
while IFS=" " read -r line1  line2; 
do
  fn1=$line1
  fn2=$line2

  cp $fn1   Data1.dat
  cp $fn2   Data2.dat

...other ext-scripts!...

done  < $FF1

This code failed copying, so as to generate those two temporary data-files! There are STILL the"error-messages for cp-operation lines"

Please help to make the two files correctly. Thx.

9
  • done > $FF1 -- you are writing to that file, not reading from. Commented Oct 5, 2019 at 3:52
  • Could you be more specific?? I'm a real-beginner of this kind of script, starting today. The problem is that this code can not copy those "Data1.dat", "Data2.dat" files...!! P.S) I'm doing an iterative works using this code to run ext-script by reading line by line from another file~!
    – David
    Commented Oct 5, 2019 at 4:09
  • @glenn The error-message: "cp: target 'Data1.dat' is not a directory; cp: missing destination file operand after 'Data2.dat'"
    – David
    Commented Oct 5, 2019 at 4:39
  • @glenn . Thanks. I got your point~! but the problem is the copying the two-files~!
    – David
    Commented Oct 5, 2019 at 4:47
  • Currently, the error-message is in cp-error : "No such file or directory~!" I confimred that the two-file names have been transfered well into "$fn1", "$fn2" from the original-list file. But still failing to generate "Data1.dat" and "Data2.dat"
    – David
    Commented Oct 5, 2019 at 5:38

1 Answer 1

2

I reproduced your kind of loop with:

while IFS="  " read -r line1 line2; do echo "cp $line1 $line2"; done <in

This produces (with a simple "in" file):

cp 111 aaaa
cp 222 bbb
cp 3333 ccccc

But if say the third line contains three names (i.e. a name with a space), you get

cp 33 33 ccccc

and now suddenly cp "switches" to the "copy several files into a directory" mode, but fails, because target "ccccc" (or 'Data1.dat') is not a directory.

cp: missing destination file operand after 'Data2.dat'

This happens after cp onefile. Something is mixing up your arguments. You have to do some tests...

The input-file has two columns for the file names.

Are you sure?

3
  • Many thanks for the comments. Yes, the main-problem is CP command is "Not copying into other files" now~!! Sure, I check the original list file's contents by printing each column it should correctly be containing the original file names. I will see/check your comments now!
    – David
    Commented Oct 5, 2019 at 6:09
  • btw: since you humbly classify yourself as "today's real beginner"...maybe you should outline your (iterative?) idea a bit more clearly? There are so many things to consider in a shell "project" like that! A good description is half the solution --- PS thanks too for the feedback
    – user373503
    Commented Oct 5, 2019 at 6:54
  • OK~! I'm a novice for the shell script's grammar. Actually, I have made numerous Monte-Carlo simulations with my C-codes, so usually, I dealt with the final data with gnuplot-scripts to generate figures. In this case, I should have to use an automatic-process for the few hundred files. Today I listed file names with conditions and paste them into a pair of files to do the more efficient fitting using the shell script. Finally, I found the way for solution~!! According to your comments,I found the reason was the delimiter problem during paste. Many thanks to your great-suggestion~!!
    – David
    Commented Oct 5, 2019 at 7:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .