1
$\begingroup$

I am trying to make a table (or grid) from a text file: filetemplate

I tried to get the numbers and the related strings using the following code:

tab1 = 
  FindList["C:\\Users\\MARCELO\\...\....txt", {"inmetro", "ufrj", "colaborador"}];

DeleteCases[tab1, {_String?(StringMatchQ[#, "Submetido"] &), ___}, Infinity]

But it does not work.

The heads table in the text file template are:

1 -         Wallclock            Média   Média

Usuário    Grupo   #jobs      dias  Porcento  #nodes  q-dias  Nome completo

2 -        Wallclock            Média   Média

   Grupo   #jobs      dias  Porcento  #nodes  q-dias

Why does StringMatchQ[#, "Submetido"]& not recognize the string "Submetido"?

I read some similar questions here, but they are not so useful on my issue.

EDIT 2 - new code that works for the first table:

 tab1 = FindList[
   "C:\\............\\...txt", {"inmetro", "ufrj", "colaborador"}];
tab2 = DeleteCases[
   tab1, _String?(StringMatchQ[#, ___ ~~ "Inic*", 
       IgnoreCase -> True] &), Infinity];
tab3 = Flatten[StringSplit[tab2, RegularExpression["\\t+"]]];
tab4 = StringDelete[tab3, 
   StartOfString ~~ Whitespace ~~ 
    "inmetro" | "ufrj" | "colaborador" ~~ ___];
tab5 = Split[tab4];
Flatten[StringSplit[#, RegularExpression["\\s{2,10}"]] & /@ tab5, 1];
tab6 = Replace[%, x_List :> DeleteCases[x, {}], {0, Infinity}];

For table 2:

    tab7 = StringCases[tab3, 
   StartOfString ~~ Whitespace ~~ 
    "inmetro" | "ufrj" | "colaborador" ~~ ___];
StringSplit[#, RegularExpression["\\s{2,10}"]] & /@ tab7;
tab8 = Flatten[
   Replace[%, x_List :> DeleteCases[x, {}], {0, Infinity}], 1];

tabfinal2 = 
 TableForm[tab8, 
  TableHeadings -> {None, {"Grupo", "jobs", "Wallclock \n dias", "%", 
     "Média\n #nodes", "Média\n q-dias"}}]
$\endgroup$

1 Answer 1

0
$\begingroup$

The real problem with your first approach was that your string pattern matches only strings which are exactly "Submetido". I guess you want to DeleteCases every string which contains "Submetido", which could be achieved with e.g.:

DeleteCases[tab1, _String?(StringMatchQ[#, ___ ~~ "Submetido" ~~ ___] &)]

Other than that you also should notice that your pattern does not really match the structure of tab1, which only is a list of strings, so neither wrapping the pattern in a list nor the level specification really make sense.

Actually you can achieve the same thing much easier with:

Select[tab1, StringFreeQ["Submetido"]]

which I think is not only shorter but also somewhat easier to understand. Of course it does implicitly assume that tab1 is a list of strings but that is what FindList will return (except for when it errors which you might need to cover anyway).

As for your EDIT: I don't have the time to look into every detail of what you do there but it certainly looks more complicated than necessary. Can you explain in plain English what you are additionally to the originial question trying to achieve there? Are you just trying to extract the numbers? Wouldn't you need them to be numbers not strings for further computation in Mathematica?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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