I am writing a Korn Shell script, where I am trying to iterate over specific lines in the
git diff result of a file. For those who don't know,
git diff lists the changes made to a file, and its output would look something like this (assuming only lines 3 and 5 changed):
unchanged line 1 unchanged line 2 - previous version of line 3 + new version of line 3 unchanged line 4 - previous version of line 5 + new version of line 5
I have stored this result in a string variable (say,
diff), and I need to iterate over each line in
diff beginning with a
+ or a
- (for instance,
- previous version of line 3). The most intuitive solution is obviously to iterate over each line in
diff and use something like
if line contains + or -, but I can't do this since
diff is not an array of separate lines, but a string separated by
\n at places.
So what I end up looking for is a way to extract each part of the string between two
How do I achieve this in Korn shell? Or maybe you guys could suggest better alternatives.