shell脚本按顺序获取o / p

时间:2015-05-24 17:23:39

标签: shell

我有文件o / p喜欢

1.2.3.4
==========
ok
1.2.3.4
===========
not good 
1.2.3.5
========
good
1.2.3.5
==========
bad

1.2.3.7
========
bad 

1.2.3.6
=========
good

1.2.3.7
=========
very good 

I need o/p like 
1.2.3.4
ok
not good 

1.2.3.5
good
bad

1.2.3.7
good
very good 

1.2.3.6
good 

任何有帮助的帮助 尝试了awk没有得到确切的o / p

1 个答案:

答案 0 :(得分:0)

cat data.txt

1.2.3.4
==========
ok
1.2.3.4
===========
not good 
1.2.3.5
========
good
1.2.3.5
==========
bad

1.2.3.7
========
bad 

1.2.3.6
=========
good

1.2.3.7
=========
very good 

| sed s/=//g

1.2.3.4

ok
1.2.3.4

not good 
1.2.3.5

good
1.2.3.5

bad

1.2.3.7

bad 

1.2.3.6

good

1.2.3.7

very good

| grep -v '^$'

1.2.3.4
ok
1.2.3.4
not good 
1.2.3.5
good
1.2.3.5
bad
1.2.3.7
bad 
1.2.3.6
good
1.2.3.7
very good

| paste - - | sort

1.2.3.4 not good 
1.2.3.4 ok
1.2.3.5 bad
1.2.3.5 good
1.2.3.6 good
1.2.3.7 bad 
1.2.3.7 very good

| tr '\n' '|' | sed 's/^/|/'

|1.2.3.4    not good |1.2.3.4   ok|1.2.3.5  bad|1.2.3.5 good|1.2.3.6    good|1.2.3.7    bad |1.2.3.7    very good |

| sed 's/|1.2.3.4//g2' | sed 's/|1.2.3.5//g2' | sed 's/|1.2.3.7//g2'

|1.2.3.4    not good    ok|1.2.3.5  bad good|1.2.3.6    good|1.2.3.7    bad     very good |

| tr '|' '\n' | sed -e 's/$/\n/' | tr '\t' '\n' | tail -n +3 | sed '$ d'

1.2.3.4
not good 
ok

1.2.3.5
bad
good

1.2.3.6
good

1.2.3.7
bad 
very good

final:

cat data.txt | sed s/=//g | grep -v '^$' | paste - - | sort | tr '\n' '|' | sed 's/^/|/' | sed 's/|1.2.3.4//g2' | sed 's/|1.2.3.5//g2' | sed 's/|1.2.3.7//g2' | tr '|' '\n' | sed -e 's/$/\n/' | tr '\t' '\n' | tail -n +3 | sed '$ d'