How would one copy only the first x lines of a csv
file into a new csv
file via the terminal?
相关问题
- How to get the return code of a shell script in lu
- sqlyog export query result as csv
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- “command not found” errors in expect script execut
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- How to read local csv file in client side javascri
- Emacs/xterm color annoyance on Linux
- Launch interactive SSH bash session from PHP
- Symfony : Doctrine data fixture : how to handle la
This might not work for you if your CSV contains "lines" containing newline seperators, e.g. in Quotes. A short PHP Script that would solve this issue, so you would get 1500 "lines"/"datasets", each possibly containing multiple "file lines"
To execute:
Brief
(You'll use a linux terminal/console)
Use
head -n NUMBEROFLINES file.csv
to get the firstNUMBEROFLINES
of lines. Write it into another file using shell redirection (>
) like this:Note that this will totally recreate
mynewfile.csv
, if it had any content before it is now deleted forever(-ish).If you ever happen to want the opposite (last x lines), use
tail
.Both tools come with man and info pages (
man head
orinfo head
- get used toman
, though) and a--help
flag (head --help
actually shows me more or less the man page).Full example
This would open the file
/tmp/first_and_last.csv
and attach (>>
,>
would recreate/delete the file!) the first and the last 10 lines ofdata.csv
at the "end" of/tmp/first_and_last.csv
.Mac OS: According to the internet (tm) these commands are available in (Unix-based) Mac OS as well (you have to start the Terminal via Finder).
More speaking examples
-n
is short for--lines=
, so you could also use: