3

In my script I am creating a temp directory with this command

TMPDIR=$(mktemp -d)

and later when I want to create a file there I use (with $DATA being my source data file)

touch $TMPDIR/data
echo "$DATA" > $TMPDIR/data

command. Later on, I use awk to alter the data with this syntax :

  awk '
    { a[i++]= ($0 * '$factor') }
    END{
     { for (j=0;j < i;j++) print a[j] }
    }
' ${TMPDIR}/data

and then I use gnuplot to plot it. But gnuplot says there are some errors and thus I wanted to print the $TMPDIR/data with cat. But it says the file doesn't exist. What do I do wrong ?

Thanks

Jesse_Pinkman
  • 565
  • 1
  • 8
  • 21
  • Did you include the `cat` into the script? Calling it from the parent shell wouldn't work, as $TMPDIR exists only in the subshell that runs the script. – choroba Apr 06 '16 at 21:15
  • yes, of course - right after the awk in the script – Jesse_Pinkman Apr 06 '16 at 21:15
  • 3
    `awk '....' $TMPDIR/data` will operate on `$TMPDIR/data` and send the output to standard out. So any changes `awk` makes aren't available in `$TMPDIR/data`. Is that what you intend? And it seems something is missing. Can you show all the lines in your script from the point where you create `$TMPDIR/data` to the point in your script where you do `cat $TMPDIR/data`? I assume `awk` generated an error because it couldn't find the file, based upon what you're saying but you didn't say what the error message was exactly. – lurker Apr 06 '16 at 21:16
  • Also, is $DATA the filename, or the file contents? – choroba Apr 06 '16 at 21:17
  • lurker - I have edited the awk script in my question and you are most certainly right - could I fix it by awking the original data file and print it out to some temp one instead ? – Jesse_Pinkman Apr 06 '16 at 21:21
  • lurker - $DATA is actually a $1 - file with data for gnuplot – Jesse_Pinkman Apr 06 '16 at 21:22
  • Post the script you executed, down to the `cat` command, so we can help you debug it. – Ed Morton Apr 06 '16 at 21:40
  • as dumb as it seems to be, lurker was right, I have forgotten to output the awk into the file I wanted to thank you all for your comments – Jesse_Pinkman Apr 06 '16 at 21:43
  • This is probably redundant, but you did `mkdir` somewhere along the line after calling `mktemp` because the latter will only create a name for a temporary directory instead of making an actual directory into your filesystem. –  Apr 10 '16 at 09:32

1 Answers1

0

I was reading through the unanswered questions and found this one. Later on reading all the comments realized that this is one of the questions already answered in the comments. The issue here was that the user has forgotten to redirect the output from the awk command to a file. To save others from reading the comments and coming to the same conclusion, I am posting this as an answer. Here is the comment which answers the question:

as dumb as it seems to be, lurker was right, I have forgotten to output the awk into the file I wanted to thank you all for your comments – Jesse_Pinkman

Jay Rajput
  • 1,813
  • 17
  • 23