awk - Pipe lines between two regex through another command -


this related another question asked.

i have text file has multiple sections. part of file looks this.

3. line 3 4. line 4  ## screenshots ##  1. line 1 2. line 2 3. line 3 4. line 4  ## changelog ##  3. line 3 4. line 4 

i want transform file, such lines of file present in transformed file , lines in screenshot section passed through command, before being added file.

so transformed file might like

3. line 3 4. line 4  ## screenshots ##  1. modified 1 2. modified 2 3. modified 3 4. modified 4  ## changelog ##  3. line 3 4. line 4 

i have following command prints lines in screenshot section. (from here)

awk '/^## screenshot/{p=1;print;next} p&&/^##/{p=0};p' readme.md  

i tested command piping output of above command , works.

but want print other lines of file untouched well. how that?

if can modify text want in awk (eg, convert "line" "modified"), directly:

awk '/^## screenshot/{p=1} p{gsub( "line", "modified")} p&&/^##/{p=0}; 1' readme.md 

if not feasible replacement in awk reason, can have awk break output , join:

awk '/^## screenshot/{f="file2"}      f=="file2" && /^##/{f="file3"}      {print > f}' f=file1 readme.md ... # perform desired filter on file2 cat file1 file2 file3 > final_output  # concatenate results 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -