title: replace strings with certain format in bash
body: <p>I have a file like this. it is a 7-column tab file with separator of one space (<code>sep=&quot; &quot;</code>).</p>
  <p>however, in the 4th column, it is a string with some words which also contains spaces. Then last 3 column are numbers.</p>
  <p>test_find.txt</p>
  <pre><code>A UTR3 0.760 Sterile alpha motif domain|Sterile alpha motif domain;Sterile alpha motif domain . . 0.0007
  G intergenic 0.673 BTB/POZ domain|BTB/POZ domain|BTB/POZ domain . . 0.0015
  </code></pre>
  <p>I want to replace <strong>space</strong> into <strong>underscore</strong> (e.g. replace &quot;Sterile alpha motif domain&quot; to &quot;Sterile_alpha_motif_domain&quot;). Firstly, find the pattern starting with letters and end with &quot;|&quot;, then treat as one string and replace all spaces to &quot;_&quot;. Then move to next line and find next patter. (Is there any easier way to do it?)</p>
  <p>I was able to use <code>sed -i -e 's/Sterile alpha motif domain/Sterile_alpha_motif_domain/g' test_find.txt</code> to only first row, but <strong>cannot generalize it</strong>.</p>
  <p>I tried to find all patterns using <code>sed -n 's/^[^[a-z]]*{\(.*\)\\[^\|]*$/\1/p' test_find.txt</code> but doesn't work.</p>
  <p>can anyone help me?</p>
  <p>I want output like this:</p>
  <pre><code>A UTR3 0.760 Sterile_alpha_motif_domain|Sterile_alpha_motif_domain;Sterile_alpha_motif_domain . . 0.0007
  G intergenic 0.673 BTB/POZ_domain|BTB/POZ_domain . . 0.0015
  </code></pre>
  <p>Thank you!!!!</p>