Skip to main content
added 10 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

One way using string patterns and StringCases like this:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace.. ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace.. ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

One way using string patterns and StringCases like this:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace.. ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}
added 2 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace.. ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace.. ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}
added 9 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<"<" >"~~ Whitespace ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

The OP mentioned in a comment to Mr.Wizard that there are a few possible patterns that will count as "NA". This is easily accommodated with this solution, e.g. using WhiteSpace as Mr.Wizard suggests.

One way using string patterns:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "< >" -> "NA",
  "True" | "False" /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}

The OP mentioned in a comment to Mr.Wizard that there are a few possible patterns that will count as "NA". This is easily accommodated with this solution, e.g. using WhiteSpace as Mr.Wizard suggests.

One way using string patterns and StringCases:

string = ImportString["<12> cfg <15.21>  bhg    v<(24)>    e<65>   True
  <12> cfg <15.21>  bhg    v<33>      e<(77)> False
  <83> fff <67>     bhg     < >       e<(43)> True
  <11> fff <14.21>  bff    v<(1.42)>  e<44>   True
  <76> cfg <76.3>   fff     < >       e<21>   True
  <98> cff <34>     rrs    v<33>       < >    True", "Lines"];
StringCases[string, {
  "<" ~~ p : NumberString ~~ ">" :> ToExpression[p],
  "<(" ~~ n : NumberString ~~ ")>" :> -ToExpression[n],
  "<" ~~ Whitespace ~~ ">" -> "NA",
  b : "True" | "False" :> b /. {"True" -> "T", "False" -> "F"}
  }]
{{12, 15.21, -24, 65, "T"}, {12, 15.21, 33, -77, "F"}, {83, 67, 
  "NA", -43, "T"}, {11, 14.21, -1.42, 44, "T"}, {76, 76.3, "NA", 21, 
  "T"}, {98, 34, 33, "NA", "T"}}
edited body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading
deleted 24 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading
added 231 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading
deleted 12 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading