0

I have a 23 folders and each folder has two subfolders (always same name) and each subfolder has exactly two files (always same name). So it looks like this:

Folder1/BindingDB/chiral.smi
                 nochiral.smi
Folder1/Xray/chiral.smi
             nochiral.smi

 Folder2/BindingDB/chiral.smi
                     nochiral.smi
 Folder2/Xray/chiral.smi
                 nochiral.smi

For example chiral.smi file looks like this:

COCCNC(=O)[C@H]1[C@@H]([C@H]2CN3C(=O)C=CC=C3[C@@H]1N2C4=NC(=C(S4)C5=CC=CC=C5)C6=CC=C(C=C6)Cl)CO K00000004
C1[C@H]2[C@H](C=C([C@H]3[C@@H]2[C@H]4[C@@H]1[C@@H]([C@H]4C=C3)CC/C=C/CC5=CC=C(C=C5)O)C(=O)O)O  K00000005
C[C@]12CCC[C@@]([C@@H]1CC[C@@]34[C@H]2C[C@H]5[C@@H](C3)[C@]5(C4)CO)(C)C(=O)O  K00000006

So here, last two lines K00000005 and K00000006 have double space and I want to match these two lines.

I am trying to double check all chiral.smi and nochiral.smi files in my folders if they have lines that have double space (I should only have one space in each line of each file).

I have tried in bash something like this:

for i in */*/*.smi ; do sed -e "s/\s\{2,\}/ /g" $i; done but it is not working. Also, when I run sed -e "s/\s\{3,\}/ /g" *smi in subfolder (BindingDB or Xray) it prints all the lines that have only one space. Can anyone help me since I cannot figure out whats the problem?

  • Are you trying to check the files - or correct them? – steeldriver May 16 '18 at 10:46
  • I am trying to check the files..but I came across the idea to open all of them in one txt file and then I just searched for double space and havent found it so it should be fine :) – sergio May 17 '18 at 2:17
1

You can list the names of any .smi files in which any line contains two adjacent spaces with

grep --include='*.smi' -rl '  ' .

If you want to output the lines themselves, then remove the l option.

0

If I understand it correctly, something like

grep -l '  ' */*/*.smi

will print the "double space" filenames

If you want do normalize spaces (' ' -> ' ') you can try to

sed -ri.bak 's/\s{2,}/ /g' */*/*.smi

and remove the backup files if all went well

rm /*/*.smi.bak

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.