0

I have a file where I want to read starting at line number 426 and ending at 2372. Within those lines I want to replace , , with a new line character and output this to a new file.

I have tried the following:

sed -n '426,2372p' input.txt > $tmpSrcFile

which works grabbing that section and outputting it but when I add the replace I can't get it to work:

sed -n '426,2372ps/:, ,:/\n/g' input.txt > $tmpSrcFile 
3
  • 1
    Try sed -n '426,2372{s/:, ,:/\n/gp}' input.txt > $tmpSrcFile
    – sseLtaH
    Aug 25, 2022 at 14:43
  • Thank you but that didn't work unfortunately
    – user538930
    Aug 25, 2022 at 17:02
  • Define 'didn't work': what did it do and how did that differ from the intended result?
    – DopeGhoti
    Aug 25, 2022 at 20:27

1 Answer 1

0

For the given input file:

1,
2,
3,
4,
5,

This sed invocation seems to replace and print only within a line range:

$ sed -n '3,4{s/,/^/gp}' input; printf "END\n"
3^
4^
END

Even when the replacement is a newline:

$ sed -n '3,4{s/,/\n/gp}' input; printf "END\n"
3

4

END

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .