Elouan  raffray Elouan  raffray - 23 days ago 4
Linux Question

awk delimiter in whole file

Input file is like this:

Scene
some
text
...
Scene
some
more
text


And i want to be able to print the text between each 'Scene' (by printing $0, $1, etc.. like a cut -d -f would do).

I tried a lot of things using awk but i don't understand how to make it work.

awk -F '^Scene' '{print $1}' file
prints the whole file,

awk '/^Scène/{ print $1 } file'
prints all the
Scene
it finds in the file.

i think i fail to understand the logic with awk.

Answer

Using gnu awk you can set a custom record separator:

awk -v RS='Scene[[:space:]]*' 'NF' file

some
text
...


some
more
text
  • -v RS='Scene[[:space:]]*' will set input record separator as Scene followed by optional white-spaces.