Searching for pattern and then counting each blank line after the pattern until the 3rd blank line is found; then I want to place a comma and a semicolon in that blank line. There could be lots of data in between the blank lines, or only one line of text in between the blank lines.GROUP DIRECTORY CATEGORIESdatadataGrouping Catdatadatadatadatathis is the 3rd blank lineI have tried the following without success. Any suggestions?sed '/GROUP DIRECTORY CATEGORIES/,/^$/^$/^$/,;/' file1>file2sed '/GROUP DIRECTORY CATEGORIES/$/$/$/,;/' file1>file2sed '/GROUP DIRECTORY CATEGORIES/{$;$;$/./,;/1;}' file1>file2
Search for pattern, then add text in third blank line
text processing;sed
While sed can be used for this, anything that involves counting is usually easier done with awk.Let's consider this test file:$ cat file1GROUP DIRECTORY CATEGORIESdatadataGrouping CatdatadatadatadataAbove is 3rd blank lineTo add a ,; to the third blank line after GROUP DIRECTORY CATEGORIES:$ awk '/GROUP DIRECTORY CATEGORIES/{f=1}  f && /^$/ {f++; if (f==4) $0=,;} 1' file1GROUP DIRECTORY CATEGORIESdatadataGrouping Catdatadatadatadata,;Above is 3rd blank lineHow it works:/GROUP DIRECTORY CATEGORIES/{f=1}Anytime that a line is found which matches the regex GROUP DIRECTORY CATEGORIES, variable f is set to 1.f && /^$/ {f++; if (f==4) $0=,;}If f is non-zero and the current line is blank, /^$/, then increment f by one.  If f is 4, then replace the current blank line with ,;.11 is awk's cryptic shorthand for print-the-line.