How to pipe the output of a sed command into a function in unix

2022-09-18T11:12:59

I have this C function that I am using to output any amount of integer that is input.

/*
  This program will be called function.c
*/

#include <stdio.h>

int main (void) {

   int num;

   while(scanf("%d",&num)==1) {
     printf("You entered: %d\n",num);
   }

   return 0;
}

In my shell the function works like this as expected with the pipe command

$echo "1 7 3 " | ./function

Output:

You entered: 1
You entered: 7
You entered: 3

Now what I'm trying to do is use the sed command on a csv file and pipe the output into my function.

Here is my CSV file

$cat file.csv

Output:

 2,2,3,3,8

Using the sed command I remove the commas

$sed 's/,/ /g' file.csv

Output:

2 2 3 3 8

Now the issue I have is when I try to use the output of the sed command to pipe the numbers into my function:

$sed 's/,/ /g' file.csv | ./function

I get no output. I don't know if there is a syntax error, but I believe I should be able to do this with a csv file.

Copyright License:
Author:「jamxy」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/73759882/how-to-pipe-the-output-of-a-sed-command-into-a-function-in-unix

About “How to pipe the output of a sed command into a function in unix” questions

I have this C function that I am using to output any amount of integer that is input. /* This program will be called function.c */ #include &lt;stdio.h&gt; int main (void) { int num; wh...
Following this answer here I'm trying to use the 'script' command to unbuffer output for use with a pipe. But it's not working as I'd expect. I have the following file: $ cat test.txt first line ...
Is there a way to conditionally pipe the output of a command through sed, in a bash script? Depending upon a script option, I either want to pipe the output of a long pipe through sed, or omit the...
I am trying to pipe output from git to sed, which will inturn replace a value in file.config that represents the last commit on a branch. I am unsure how to do this using piping in bash. I thought ...
Sed command is not working in Unix for file size greater that 3GB, to remove carriage return and new line character from the file. I am trying to remove the new line character from a pipe delimite...
I am new to UNIX and was going through a script file and came accross a snippet. I tried to analyze the snippet. I read a bit about the 'sed - stream editor' command also the sed -e option. I also
If I start a process in parallel with joblib that calls a subprocess with a unix pipe (sed | uniq | blabla) many of those processes write error messages to the terminal after having sucessfully exi...
I have a simple file like : a 123 b 234 In a second file, I want to replace a string by the value corresponding to a -> "123" in a single command. Is there a way to pipe the result of grep "a" f...
Input file hello how are u some what doing fine so thats all huh thats great cool gotcha im fine I wanted to remove last 4 lines without re directing to another file or say in place edit. I u...
I'm new to the Unix sed command and I would like to know how to double the first digit in a string? Suppose we have a string "F0o", How do I double the first digit in the string? I tried echo f0o...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.