打印特定列和其余列

时间:2016-03-08 12:46:55

标签: awk

这是我目前的意见:

12 01 2016   "TEST-12345" "Bug"  12 01 2016   "Here are some words with spaces" "No" "No"

目前我正在使用此命令:

cat DATEI | awk '{print $3"."$2"."$1,$4,$5,$8"."$7"."$6}'

但我不会得到最后一列"Here are some words with spaces" "No" "No"。当然,我可以做$9,$10,$11,$12,$13...$100,但这不是一个好的解决方案。

我的目标是获得以下输出:

2016.01.12 "TEST-12345" "Bug" 2016.1.12 "Here are some words with spaces" "No" "No"

你有什么想法吗?

2 个答案:

答案 0 :(得分:3)

awk -F '"' -v OFS='"' '{split($1, a, " ");$1=a[3]"."a[2]"."a[1]" ";$5=" "$1;print $0}'

"用作IFSOFS,并将第一个字段$1与分隔符分隔为数组a的空格。并使用数组a中的值重新分配$ 1和重新定位的值。同样对$5也这样做。在此,我假设$5$1相同,否则使用$5的其他拆分。

答案 1 :(得分:0)

如果你只想检查类似日期的字符串,而你没有其他日期,你不想在文本中转换,你可以只使用sed:

<DataGrid ItemsSource="{Binding Countries}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Country" Binding="{Binding Name}"/>
    </DataGrid.Columns>
    <DataGrid.RowHeaderTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding DataContext.Continent, 
                        RelativeSource={RelativeSource AncestorType=DataGridRow}}"></TextBlock>
        </DataTemplate>
    </DataGrid.RowHeaderTemplate>
</DataGrid>

使用sed -E -e 's/([[:digit:]]{2}) ([[:digit:]]{2}) ([[:digit:]]{4})/\3.\2.\1/g' DATEI 代替-r进行GNU sed。

相关问题