简体   繁体   中英

Using Bash Scripting to save output in an csv file

I prepared a .sh file that runs a C program and print the result in an external file. Here is my code:

#!/bin/bash

min=-2
max=2

(echo $min; echo $max) | CFiles/main > main_data.csv

The only problem is that I don`t want the sentences "Enter the minimum value" and "Enter the maximum value" to be printed in the csv file. I only want the data generated by the program after it receives the input values. What should I do?

The source of main is:

#include <stdio.h>
#include "c_operations.h"

int main(void) {

  INT i, j, out;
  const VALUE min, max;
  COMPLEX z;
  PLANE a;

  printf("Enter the minimum value: ");
  scanf("%Lf", &min);
  printf("\n");
  printf("Enter the maximum value: ");
  scanf("%Lf", &max);
  printf("\n");

  a = constructor(min, max);

  for(i=0; i<100; i++){
    for(j=0; j<100; j++){
      z = get(&a, i, j);
      out = iterate(z, 0);
      printf("%Lf, %Lf, %ld\n", z.x, z.y, out);
    }
  }

  delete_plane(a);

  return 0;
}

Best answer, take @miken32's suggestion.

Otherwise, just add a filter to remove the first 2 lines of the output:

{ echo $min; echo $max; } | CFiles/main | sed '1,2d' > main_data.csv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM