Select 输出的每一行中特定列之间的文本

Select text between specific columns in everyline of the output

我的输出类似于:

xxxxxxxxxFOOxxxxxxxxxxxx
blablabl BAR lablblablaa
=========tst============

我能做些什么来获得类似的东西:

FOO
BAR
tst

我应该使用哪个命令来仅显示所有行中特定列之间的文本?

cut -d 将不起作用,因为它在每一行中的分隔符都不相同..

PS : 它在 android 上并且错过了几个命令..

感谢帮助...

String[] str = {"xxxxxxxxxFOOxxxxxxxxxxxx",
                "blablabl BAR lablblablaa",
                "=========tst============"};

for (String s : str) {
  int half = s.length() / 2;
  String cutted = s.substring(half - 3, half);
  // or String cutted = s.substring(9, 12);
  // => FOO, BAR, tst
}

cut -d will not work cause its not the same delimiter in every lines ..

是,但 cut -c10-12 完成了这项工作,仅提取每行的第 10、11 和 12 个字符。你没有提供更长行的例子,所以不清楚你想在那种情况下做什么。

使用像这样的简单方法:

private static String selectBetween(String input, int numberOfCharacters) {
    int startIndex = (input.length() - numberOfCharacters) / 2;
    return input.substring(startIndex, startIndex + numberOfCharacters);
}

然后你就这样调用:String output = selectBetween("123123ABC123123", 3);// output will be ABC