Use sed
to split a single patch file into multiple ones using line numbers
Let's say you have a patch file like this one and you want to split it into multiple patch files for some reason. This is easily done using sed
:
First, determine the line numbers. For a unified diff like the above:
$ grep -n -- '^diff ' ~/tmp/ueberzug-18.1.9.patch
1:diff -urN ueberzug-18.1.9.orig/Xshm/Xshm.c ueberzug-18.1.9/Xshm/Xshm.c
22:diff -urN ueberzug-18.1.9.orig/examples/fzfimg.sh ueberzug-18.1.9/examples/fzfimg.sh
34:diff -urN ueberzug-18.1.9.orig/ueberzug/query_windows.py ueberzug-18.1.9/ueberzug/query_windows.py
55:diff -urN ueberzug-18.1.9.orig/ueberzug/xutil.py ueberzug-18.1.9/ueberzug/xutil.py
$
Now, you can sed
to split that patch into 3 or 4 pieces (depending on whether you want a patch for each directory, or one for each file, respectively):
$ sed -n \
'1,21w 1.patch
22,33w 2.patch
34,54w 3.patch
55,$w 4.patch' \
~/tmp/ueberzug-18.1.9.patch
$ ls
1.patch 2.patch 3.patch 4.patch
$