title: Removing spaces from the fields in a pipe-delimited file using shell script
body: <p>I am new to UNIX Shell scripting.</p>
  
  <p>I need help in removing leading and trailing blank spaces from the fields. But I need to retain the spaces between the words.</p>
  
  <p>Please have a look at the data sample and the desired result below to understand my problem.</p>
  
  <p>Data Sample :</p>
  
  <pre><code>1-B48980007       |82984788|317      |ALQ|     |4423271    |              0|  |
  
  I0000000000000000000245729|28887957|IL FR    |   |     |00000000573|              0|  |
  
  I0000000000000000000245715|13822348|RPVIPPR  |   |     |00000000298|              0|  |
  
  I0000000000000000000245721|15348717|AN BV    |   |     |00000001526|              0|  |
  </code></pre>
  
  <p>Desired Result:</p>
  
  <pre><code>1-B48980007|82984788|317|ALQ||4423271|0||
  
  I0000000000000000000245729|28887957|IL FR|||00000000573|0||
  
  I0000000000000000000245715|13822348|RPVIPPR|||00000000298|0||
  
  I0000000000000000000245721|15348717|AN BV|||00000001526|0||
  </code></pre>
  
  <p>But I am getting the output as below on using the below command:</p>
  
  <p>sed 's/ *\|/\|/g' file_name > testOP</p>
  
  <p>pipeline('|') is a delimiter in my file. I need to remove the spaces before and after the pipeline but need to retain the spaces between the words for example: "IL FR" and "AN BV".</p>
  
  <pre><code>1-B48980007     |82984788|317|ALQ||4423271|           0||
  
  I0000000000000000000245729|28887957|IL FR|  ||00000000573|            0||
  
  I0000000000000000000245715|13822348|RPVIPPR|    ||00000000298|            0||
  
  I0000000000000000000245721|15348717|AN BV|  ||00000001526|            0||
  </code></pre>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks,
  Savitha</p>