Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

lowest priority
very high significance.
outstanding
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
add comment

3 Answers

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
add comment

Also, awk is pretty straightforward:

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

Your Answer

 
discard

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.