title: How to delete \n from the end of some particular lines in file [shell]?
body: <p>In Redhat I have file.csv that has below data:</p>
  
  <pre><code>170033101;20170302;;;"Free text 1"
  170033101;20170302;;;"Free text 2"
  170033101;20170302;;;"Free 
  text 3"
  170033101;20170302;;;"Free text 4"
  </code></pre>
  
  <p>I want to create another corrected file (Correct_file.csv) after removing the wrong \n from the file to be as below:</p>
  
  <pre><code>170033101;20170302;;;"Free text 1"
  170033101;20170302;;;"Free text 2"
  170033101;20170302;;;"Free text 3"
  170033101;20170302;;;"Free text 4"
  </code></pre>
  
  <p>My solution:</p>
  
  <p>I made the below shell script to find rows preceding those lines that don't start with 170, and then create sed.txt that has a sed line for each wrong row to replace the \n with space.</p>
  
  <p>I am unable to perform the sed command or tr command to remove a specific line based on the line number</p>
  
  <p>My Script:</p>
  
  <pre><code>&gt;sed.txt;
  for i in `grep -nv '^[1706]' $1|cut -f 1 -d \:`
  do
  if [ $i -eq 1 ]
  then
  continue
  else
  j=`expr $i - 1`
  echo $j"s/\n//" &gt;&gt;sed.txt
  fi
  done
  sed -f sed.txt $1 &gt;$2
  </code></pre>
  
  <p>I call the script and pass 2 parameters 1- old file 2- new corrected file, and the new file is exactly as the old with no correction.</p>