1

I'm attempting to replace the beginning of lines in a simple file.

>1
TGAACCATCGAGTCTTTGAACG
>2
GAGTTCATTTCTCTCTGGAGGCACC
>3
ATTGACAGATTGAGAGCTCTTTC
>4
CGGGAAAAGGATTGGCTC
>5
TCTTGGTGGTAGTAGCAAATATTCAAATG

Above is the input, below is the desired output.

>seq_x1
TGAACCATCGAGTCTTTGAACG
>seq_x2
GAGTTCATTTCTCTCTGGAGGCACC
>seq_x3
ATTGACAGATTGAGAGCTCTTTC
>seq_x4
CGGGAAAAGGATTGGCTC
>seq_x5
TCTTGGTGGTAGTAGCAAATATTCAAATG

Here is the command I've tried using:

sed -n -r 's/^>(\d+)/>seq_x\1/' file

Using text editors on a small subset of the file, I have no problem with find and replace using '^>(\d+)' and '>seq_x\1', but I can't get sed to replace effectively. Is there something I'm missing?

underasail
  • 63
  • 1
  • 8

1 Answers1

1

In your simple case there's no need to specify a followed digit.
Besides, you should use a more portable [0-9] (range of numbers) instead of \d+.

sed 's/^>/>seq_x/' file
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105