Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently, I have a plain text file, A, such as

lowest priority
very high significance.
very novel

In this file, every line contains a sentence. I want to separate this file into multiple files, and each file is composed of a single line of the original file, A. For instance, with respect to the example file A, I want to generate four files:

  • A1, which has single line, lowest priority
  • A2, which has single line, very high significance
  • A3, which has single line, outstanding
  • A4, which has single line, very novel.

How to do that under linux?

share|improve this question
up vote 5 down vote accepted

You can easily do it using split command. E.g.:

split -l1 -d -a 3 A A

Check man split for details.

share|improve this answer

Also, awk is pretty straightforward:

awk '{filename = FILENAME NR; print > filename; close(filename)}' A
share|improve this answer
n=1; while IFS= read -r line; do printf %s\\n "$line" > A$n; n=$((n+1)); done <A
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.