LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sed command went super wrong, please help (https://www.linuxquestions.org/questions/linux-newbie-8/sed-command-went-super-wrong-please-help-4175657070/)

esantillan 07-08-2019 03:57 PM

Sed command went super wrong, please help
 
Hi everyone, I'm very new at GNU Linux, so I used a sed command wrongly, I ended up messing all my most important files, the idea was to change all special characters in the file's names, but ended up changing all special characters inside the files.

This is the command:

Code:

sed -i 'y/αΑΰΐγΓβΒιΙκΚνΝσΣυΥτΤϊΪρΡηΗ/aAaAaAaAeEeEiIoOoOoOuUnNcC/' Docs/superimportant_files/*
There are 1400 files, which have are .pdf and the other have are .doc

I need to undo this, but I can't. I need big help.

esantillan 07-08-2019 03:59 PM

I haven't done anything else with those files, at all, since the dumb accident.

MadeInGermany 07-08-2019 04:03 PM

The attempt to rerun the sed -i with swapped sides will likely fail, because it cannot distinguish between the produced destination characters and the destination characters that have already been there.
Restore from backup!

rtmistler 07-08-2019 04:03 PM

I'd start by making backups of what you do have, searching for any former good copies of the files, and setting them all aside so as to not cause more troubles.

Then I'd try the reverse of that command only on a copy of one file and see if it fixes it:
Code:

sed -i 'y/aAaAaAaAeEeEiIoOoOoOuUnNcC/αΑΰΐγΓβΒιΙκΚνΝσΣυΥτΤϊΪρΡηΗ/' <filename>
Note that sed does NOT change your file names, it changes the contents of files. Use the rename(2) command instead.

scasey 07-08-2019 04:06 PM

You don't have a backup to restore from, then?

Backup your files before you try anything else.

man sed says
Code:

-i[SUFFIX], --in-place[=SUFFIX]
    edit files in place (makes backup if SUFFIX supplied)

Reverse the sed, perhaps?
Code:

sed -i.bak 'y/aAaAaAaAeEeEiIoOoOoOuUnNcC/αΑΰΐγΓβΒιΙκΚνΝσΣυΥτΤϊΪρΡηΗ/' Docs/superimportant_files/*
Edit: rtmistler and MadeInGermany are quicker than I ;)

syg00 07-08-2019 06:56 PM

Both pdf and doc files are compressed, not plain text, so the damage is more than simply cosmetic. I agree with the sentiments in post #3.


All times are GMT -5. The time now is 04:38 PM.