Split a file into multiple files based on a pattern and name the new files by the search pattern in Unix?

后端 未结 2 1644
慢半拍i
慢半拍i 2021-01-21 23:28

How can I split a file based on a search pattern and the new files that will be generated will have the file names as equal to the search pattern which was used to split the fil

2条回答
  •  伪装坚强ぢ
    2021-01-22 00:23

    Just a note to people that might have a large number of files that have to be generated. Your command will crash unless you close the previously generated file first, so the improved version of Juan Diego Godoy's answer would be:

    awk '/^GROUP[0-9]+$/{close(x);x=$0}{print > x;}' cdw_all_jobs_reduced3.txt
    

提交回复
热议问题