Artificial intelligent assistant

sed modifying in place with -i flag I'm new to `GNU sed` (running on macOS) and wish to shorten some file headers (~50 K headers, 78.3 Mb). I'm trying to modify FASTA files in place by specifying a backup extension with the `-i` flag. So far I have sed -i.bak 's/^([^|]+).[^|]+(.*)/\1\2/' file.fas which should create a new file called `file.fas.bak`. However, I'm getting the error sed: 1: "s/^([^|]+).[^|]+(.*)/\1\2/": \1 not defined in the RE Note `sed -re 's/^([^|]+).[^|]+(.*)/\1\2/' file.fas` prints correctly to screen. Any ideas on how to print to a backup file in this case?

You have to specify the `-r` option, too, in order to enable interpretation of extended regular expression syntax ( **but note** that `-E` is more portable than `-r` and will soon supersede it), so you should use


sed -E -i.bak 's/^([^|]+).[^|]+(.*)/\1\2/' file.fas


Alternatively, resort to basic regular expressions:


sed -i.bak 's/^\([^|]\{1,\}\).[^|]\{1,\}\(.*\)/\1\2/' file.fas


**Update**

In a reply to @terdon's question you confirmed that the files are FASTA files. In that case, you may improve efficiency by only considering header lines (those starting with `>`), as proposed by @terdon:


sed -E -i.bak 's/^(>[^|]+).[^|]+(.*)/\1\2/' file.fas

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d0d7f34999b35d1146c08fd0245cea83