LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed creating an extra file with e at the file name (https://www.linuxquestions.org/questions/linux-newbie-8/sed-creating-an-extra-file-with-e-at-the-file-name-4175540543/)

publicLearner 04-23-2015 11:36 AM

sed creating an extra file with e at the file name
 
Hi Members,

I've file named A200205__mlst__Staphylococcus_aureus__results.txt
It has column 1 as:

Quote:

Sample
A200205_GGTGAGTT_L007
I'm running below command:
Quote:

sed -ie s/out_paired_//g A200205__mlst__Staphylococcus_aureus__results.txt
It replaces out_paired_ in line 2 of column 1 to null.
I'm having the desired output, however, surprisingly a new file is created with name A200205__mlst__Staphylococcus_aureus__results.txte; i.e an extra e

I am unable to figure it out the cause of this hack!

millgates 04-23-2015 11:45 AM

the sed manpage says:

Code:

      -i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if SUFFIX supplied)

that is, the -i switch replaces the contents of the file passed as argument instead of writing to standard output. However, if you supply a suffix to -i, sed creates a backup of the original file with the suffix appended to the filename.
So, in this case, you used an -ie switch and the "e" is interpreted as the suffix for the -i switch.
If you want to avoid this, separate the switches:
Code:

sed -i -e ...

publicLearner 04-23-2015 12:31 PM

Hi millgates,
Thanks.

That worked like charm.
Got to be reading MAN pages more closely. :study: :redface:


Quote:

Originally Posted by millgates (Post 5351938)
the sed manpage says:

Code:

      -i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if SUFFIX supplied)

that is, the -i switch replaces the contents of the file passed as argument instead of writing to standard output. However, if you supply a suffix to -i, sed creates a backup of the original file with the suffix appended to the filename.
So, in this case, you used an -ie switch and the "e" is interpreted as the suffix for the -i switch.
If you want to avoid this, separate the switches:
Code:

sed -i -e ...



All times are GMT -5. The time now is 02:18 AM.