How to write the shell command to skip the first line in file a.csv
and redirect the remaining lines as input to myProgram
, which is my C program?
I wrote
./myProgram < a.csv | tail -n + 2
But this does not work, it seems like it will skip the first line of the output from myProgram
.
In most C compilers, including ours, the newline escape sequence '\n' yields an ASCII line feed character. The C escape sequence for a carriage return is '\r'.
The first line of a file can be skipped by using various Linux commands. As shown in this tutorial, there are different ways to skip the first line of a file by using the `awk` command. Noteably, the NR variable of the `awk` command can be used to skip the first line of any file.
To look at the first few lines of a file, type head filename, where filename is the name of the file you want to look at, and then press <Enter>. By default, head shows you the first 10 lines of a file. You can change this by typing head -number filename, where number is the number of lines you want to see.
Erm...
tail -n +2 a.csv | ./myProgram
If you want to skip the first line, the traditional solution is sed
:
sed -e 1d a.csv | ./myProgram
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With