sed - How to assign number for a repeating pattern -


i doing calculations using gaussian. gaussian output file, need extract input structure information. output file contains more 800 structure coordinates. did far is, collect input coordinates using combinations of grep, awk , sed commands, so:

grep -a 7 "input orientation:" test.log | grep -a 5 "c" | awk '/c/{print "structure number"}1' | sed '/--/d' > test.out 

this helped me grep input coordinates , insert line "structure number". have file contains pattern being repeated in regular fashion. file following:

structure number

4.176801 -0.044096 2.253823

2.994556 0.097622 2.356678

5.060174 -0.115257 3.342200

structure number

4.180919 -0.044664 2.251182

3.002927 0.098946 2.359346

5.037811 -0.103410 3.389953

here, "structure number" being repeated. want write number "structure number:1", "structure number 2" in increasing order.

how can solve problem?

thanks in advance.

i not familiar @ program called gaussian, have no clue original input looked like. if posts example might able give shorter solution.

however, far got op contented output of his/her code besided he/she wants append increasing number lines inserted awk.

this can achieved following line (adjusting op's code):

grep -a 7 "input orientation:" test.log | grep -a 5 "c" | awk '/c/{print "structure number"++i}1' | sed '/--/d' > test.out 

addendum:

even without knowing actual input, sure 1 can @ least rid of sed command leaving piece of work awk. also, there no need quote single character grep pattern:

grep -a 7 "input orientation:" test.log | grep -a 5 c | awk '/c/{print "structure number"++i}!/--/' > test.out 

i not sure since cannot test, should possible let awk grep's work, too. first guess try following:

awk '/input orientation:/{li=7}!li{next}{--li}/c/{print "structure number"++i;lc=5}!lc{next}{--lc}!/--/' test.log > test.out 

while might little bit longer in code awk-only solution doing work in 1 process. if had input test with, might come shorter solution.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -