How to grep two numbers from the same line at different places using bash? - Ask Ubuntu


i want grep 2 numbers same line in example below:

// examplefile.txt solver.cpp:229] iteration 2000, loss = 0.305721 solver.cpp:245]     train net output #0: accuracy = 0.926112 solver.cpp:245]     train net output #1: accuracy = 0.723957 solver.cpp:245]     train net output #2: accuracy = 0.599623 sgd_solver.cpp:106] iteration 2000, lr = 0.000227383 solver.cpp:229] iteration 2020, loss = 0.294722 solver.cpp:245]     train net output #0: accuracy = 0.855208 solver.cpp:245]     train net output #1: accuracy = 0.71616 solver.cpp:245]     train net output #2: accuracy = 0.619429 

i need number right of "solver.cpp:229] iteration " , right of ", loss = ". need both numbers @ same time such resulting file looks this:

// resultfile.txt 2000 0.305721 2020 0.294722 

i know how 1 of numbers using grep

grep ", loss = " examplefile.txt | sed -e "s/.* //" > resultfile.txt 

does know how second number simultaneously?

one possible way...

% grep 'solver.cpp:229' examplefile.txt | cut -d ' ' -f 3,6 | tr -d ',' 2000 0.305721 2020 0.294722 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User