Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip first line of a file and read the remaining lines as input of a C program?

Tags:

linux

shell

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.

like image 896
John Avatar asked Oct 19 '16 01:10

John


People also ask

How do you skip a line in C?

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'.

How do you skip the first line of a file in Shell?

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.

How do you get the first line from a file using just the terminal?

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.


2 Answers

Erm...

tail -n +2 a.csv | ./myProgram
like image 124
Ignacio Vazquez-Abrams Avatar answered Sep 25 '22 17:09

Ignacio Vazquez-Abrams


If you want to skip the first line, the traditional solution is sed:

sed -e 1d a.csv | ./myProgram
like image 32
William Pursell Avatar answered Sep 26 '22 17:09

William Pursell