Help with sed or maybe awk? Substitute a line before a match

I’m creating this script to manipulate FDF files to fill forms in PDF files. What I need to happen is each day of the week the script looks for a specific field to fill, the format of an FDF file is as follows

<<
/V (value or string to fill a field)
/T (title of the field)
>>

The script needs to find the title of the field, go up a line and add the value for that field. I can easily append or insert text but that creates a whole new line in the document and breaks the format so that doesn’t work.

I thought maybe I could find the exact line number, subtract 1 from it, store that in a variable and use a regular sed '125s/thing1/thing2/' line specific replacement where “125” is the line number stored in the $variable.

Can sed do this? or maybe awk is a better solution. I have no idea what the best way to accomplish this is. Bonus points for POSIX, eventually I’ll be running this on a FreeBSD tty.

Maybe this will help.

1 Like

Thanks @jeffrey I think that solves it. I wonder why my searches never came up with that page?