stringsedzos

How to insert a new line after a certain row number in a file in environment z/OSS USS (OMVS)


I am working in a USS environment, under z/OS. I need to insert a new line in a file, the line has to be inserted after a certain row number.

I've tried to use the command sed '4i\newtext' file.txt but I've got the error FSUM7301 '"\" must terminate the "character" command'.

I've tried to put the additional \ after the i, after the newtext, but nothing worked.

It's the same for the option a instead of i.

How can it be done?

I'm new to programming in bash in OMVS environment. In bash on Linux the comand sed 4i\newtext file.txt works perfectly, also the option a (one insert before and the other after the line 4).


Solution

  • I don't have access to z/OS and I don't understand the FSUM7301 "" must terminate the "character" command but according to sed POSIX specification the text inserted must be on the newline so maybe try this:

    sed '4i\
    newtext' file.txt