Score:0

Grep a block of lines from a file

as flag

I want to extract only blocks of lines from a file that has over 5000 blocks of such lines. How can I use grep to do that?

ATOMIC_POSITIONS crystal
 Ti   0.3333335000000000  0.1666670000000000  0.4568808285000000
 Ti   0.8333334999999999  0.1666670000000000  0.4568808285000000
 Ti   0.3333335000000000  0.6666670000000000  0.4568808285000000
 Ti   0.8333334999999999  0.6666670000000000  0.4568808285000000
 Ti   0.3333335000000000  0.1666670000000000  0.9568808285000000
 Ti   0.8333334999999999  0.1666670000000000  0.9568808285000000
 Ti   0.3333335000000000  0.6666670000000000  0.9568808285000000
 Ti   0.8333334999999999  0.6666670000000000  0.9568808285000000
 Ti   0.1666665000000000  0.3333330000000000  0.2068808285000000
 Ti   0.6666665000000001  0.3333330000000000  0.2068808285000000
 Ti   0.1666665000000000  0.8333330000000000  0.2068808285000000
 Ti   0.6666665000000001  0.8333330000000000  0.2068808285000000
 Ti   0.1666665000000000  0.3333330000000000  0.7068808285000000

 Ti   0.6666665000000001  0.3333330000000000  0.7068808285000000
 Ti   0.1666665000000000  0.8333330000000000  0.7068808285000000
 Ti   0.6666665000000001  0.8333330000000000  0.7068808285000000
 Ti   0.1666665000000000  0.3333330000000000  0.0431191715000000
 Ti   0.6666665000000001  0.3333330000000000  0.0431191715000000
 Ti   0.1666665000000000  0.8333330000000000  0.0431191715000000
 Ti   0.6666665000000001  0.8333330000000000  0.0431191715000000
 Ti   0.1666665000000000  0.3333330000000000  0.5431191715000000
 Ti   0.6666665000000001  0.3333330000000000  0.5431191715000000
 Ti   0.1666665000000000  0.8333330000000000  0.5431191715000000
 Ti   0.6666665000000001  0.8333330000000000  0.5431191715000000
 Ti   0.3333335000000000  0.1666670000000000  0.2931191715000000
 Ti   0.8333334999999999  0.1666670000000000  0.2931191715000000
 Ti   0.3333335000000000  0.6666670000000000  0.2931191715000000
 Ti   0.8333334999999999  0.6666670000000000  0.2931191715000000
 Ti   0.3333335000000000  0.1666670000000000  0.7931191715000000
 Ti   0.8333334999999999  0.1666670000000000  0.7931191715000000
 Ti   0.3333335000000000  0.6666670000000000  0.7931191715000000
 Ti   0.8333334999999999  0.6666670000000000  0.7931191715000000
 Cd   0.3333335000000000  0.1666670000000000  0.1250000000000000
 Cd   0.8333334999999999  0.1666670000000000  0.1250000000000000
 Cd   0.3333335000000000  0.6666670000000000  0.1250000000000000
 Cd   0.8333334999999999  0.6666670000000000  0.1250000000000000
 Cd   0.3333335000000000  0.1666670000000000  0.6250000000000000
 Cd   0.8333334999999999  0.1666670000000000  0.6250000000000000
 Cd   0.3333335000000000  0.6666670000000000  0.6250000000000000
 Cd   0.8333334999999999  0.6666670000000000  0.6250000000000000
 Cd   0.1666665000000000  0.3333330000000000  0.3750000000000000
 Cd   0.6666665000000001  0.3333330000000000  0.3750000000000000
 Cd   0.1666665000000000  0.8333330000000000  0.3750000000000000
 Cd   0.6666665000000001  0.8333330000000000  0.3750000000000000
 Cd   0.1666665000000000  0.3333330000000000  0.8750000000000000
 Cd   0.6666665000000001  0.3333330000000000  0.8750000000000000
 Cd   0.1666665000000000  0.8333330000000000  0.8750000000000000
 Cd   0.6666665000000001  0.8333330000000000  0.8750000000000000
  C   0.0000000000000000  0.0000000000000000  0.0000000000000000
  C   0.5000000000000000  0.0000000000000000  0.0000000000000000
  C   0.0000000000000000  0.5000000000000000  0.0000000000000000
  C   0.5000000000000000  0.5000000000000000  0.0000000000000000
  C   0.0000000000000000  0.0000000000000000  0.5000000000000000
  C   0.5000000000000000  0.0000000000000000  0.5000000000000000
  C   0.0000000000000000  0.5000000000000000  0.5000000000000000
  C   0.5000000000000000  0.5000000000000000  0.5000000000000000
  C   0.0000000000000000  0.0000000000000000  0.2500000000000000
  C   0.5000000000000000  0.0000000000000000  0.2500000000000000
  C   0.0000000000000000  0.5000000000000000  0.2500000000000000
  C   0.5000000000000000  0.5000000000000000  0.2500000000000000
  C   0.0000000000000000  0.0000000000000000  0.7500000000000000
  C   0.5000000000000000  0.0000000000000000  0.7500000000000000
  C   0.0000000000000000  0.5000000000000000  0.7500000000000000
  C   0.5000000000000000  0.5000000000000000  0.7500000000000000
Romeo Ninov avatar
in flag
Can you provide please the expected result. From what you provide it is not clear what these 5000 blocks means.
Bill C Oyomo avatar
as flag
I need all blocks containing the Atomic_positions from a file that has a bunch of texts and Different atomic_positions
Romeo Ninov avatar
in flag
In such case please provide clear input file with possible text, combinations, etc. And expected output. You may snip the repeating text
Score:0
in flag

I'm guessing that you're looking for somthing to handle groups of data separated by blank lines?

Based on this assumption I think what you actually might be looking for could be awk (and not grep). Specifically this might be just the thing: https://www.gnu.org/software/gawk/manual/html_node/Multiple-Line.html

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.