Bash: copying lines with specific character to files with same name as copied line.

I am trying to make my script as simple as a possible but, I am not sure if the way I am approaching is necessarily the most efficient or effective it can be. What I am mainly trying to fix is a for loop to remove a string from the specified files and within this loop I am trying to copy the lines with a specific character from the files to another set of files with a particular extension. I have found somethings similar using copy but only piping to one file.

This is what I have so far but because the files I want to copy from and the files I want to copy to have different extension names I am not sure how to use their basenames...

for i in /home/path/to/*.file

do
      sed -i 's/.pattern//g' "$i"
      grep '>' "$i" > *_relabeled
done

Here 'i' is all lines where ".pattern" is removed and I want to copy these lines to '_relabeled'. I want '_relabeled' (the ) to expand to the same name that is used for "/home/path/to/.file" with a different extension

Would it be better to do the two separately or is there a better way to modify what I currently have? Is there some way to link or extract string that is associated with the '>' to be used as the file identifier to paste this string?

Thank you!

Not sure I entirely understand what you're up to. In bash , you can use "parameter expansion" to extract a file name from a path, like ${i##*/} . What exactly do you expect *_relabeled to expand to?

The loop runs for all files. Within the loop you only need to handle one file (indicated by $i).

  grep '>' "$i" > "$i"_relabeled