Month Name Marks
2016-10 Sam 58
2016-09 Sam 77
2016-10 John 64
2016-09 John 47
2016-10 Mark 71
2016-09 Mark 38
2016-10 Steve 83
2016-09 Steve 39 我从我的数据库中获取这个数据,第一列中有一个月,第二列中每个学生在第三列中都有标记。现在我想用这样的方式编辑,在第一栏中包含名称,在第二栏中包含2016-10的标记,在第三列中包含2016-09的标记。
发布于 2016-10-15 20:25:58
如果你需要两个月
sed '
2~2{ #for even lines
N #attach next line
s/\(\S\+ \)\(\S\+ \)[0-9]*\n\(\S\+\).*/\2\1\3/ #rearrange two line
}
1c\Name Month1 Month2 #output new header
' file.data或双重标记
sed '
1!N #from second line attach next line
s/\S\+ // #remove first field (2016-10)
s/\n.* / / #remove 2 fields in attached line
t #ommit 1st line
s/$/1 Marks2/ #arrange header
' file.data其他版本
echo 'Name Marks1 Marks2' ;\
paste -sd' \n' <(tail -n +2 file.data) |
cut -d' ' -f 2,3,6https://unix.stackexchange.com/questions/316637
复制相似问题