I have a txt file and I want to use the sed command in the following points:

  1. For the first 5 songs in the file, change the song name to uppercase. My solution was:
cat file.txt | sed -r 's/.*/\U&/'
  1. With lines that contain "Font1" append the line "is bold." My solution was:
cat file.txt | sed 'Font1 a\ is bold'

Hope you got my point, and thanks in advance.

1 Answer 1


You should add addresses to your commands:

sed -r '1,5 s/.*/\U&/; /Font1/ a\ is bold' file.txt

This specifies the address range line1 to 5 for the first command, and lines that match Font1 for the second. Be aware that Font1 in the first five lines will be converted first and thus not be matched by the second address definition. By the way, sed is capable of reading files by itself, no need for the cat. And, as you see, all commands can go into one single sed script.

  • I think you can still search for Font1|FONT1 or /Font1/i to avoid that issue.
    – seshoumara
    Dec 8, 2022 at 3:19

You must log in to answer this question.

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