I have a file in which a pattern (eg: RotX) is repeated many times in a similar context. I need to insert a specific text (eg: Rot-X) at the start of every line which is located five lines before every pattern match:
...
_face_641
{
type wall;
nFaces 6;
startFace 63948413;
inGroups 1(RotX);
}
_face_821
{
type wall;
nFaces 3;
startFace 63948419;
inGroups 1(RotX);
}
_face_67
{
type wall;
nFaces 3;
startFace 63948422;
inGroups 1(RotX);
}
...
should become
...
Rot-X_face_641
{
type wall;
nFaces 6;
startFace 63948413;
inGroups 1(RotX);
}
Rot-X_face_821
{
type wall;
nFaces 3;
startFace 63948419;
inGroups 1(RotX);
}
Rot-X_face_67
{
type wall;
nFaces 3;
startFace 63948422;
inGroups 1(RotX);
}
...
Could this be done using sed or awk ?
Many thanks in advance for your help
_withRot-X? Or does the pattern within your parentheses vary such that it's not alwaysRot-XwhereRotXis found 5 lines later?