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.

  • 2
    Please provide a sample of your input and expected output.
    – MelBurslan
    Mar 16, 2016 at 17:34
  • 2
    You can't do that just with csplit, you'll have to either rename the pieces after splitting or use a more advanced tool like awk or perl. Mar 16, 2016 at 19:13

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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