Is there a way to set output names of csplit
through the pattern?
I want to split the ssh-config by hosts to corresponding files.
If there is a solution without csplit
I'm happy as well.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs there a way to set output names of csplit
through the pattern?
I want to split the ssh-config by hosts to corresponding files.
If there is a solution without csplit
I'm happy as well.
No, csplit
can only use integer numbering in output file names. If you want to base the output file on the content, use another tool, for example awk or perl.
awk '
BEGIN {out="_"}
$1 == "Host" {if ($2 ~ /\//) exit(1); out=$2}
{print >out}'
Note that this code only performs rudimentary error checking (I did at least make sure that it would only write in the current directory). Don't run it on an untrusted file.
csplit
, you'll have to either rename the pieces after splitting or use a more advanced tool likeawk
orperl
.