Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Need to add a new line between string of numbers and letters

    I have a file that reads something like:

    I need to insert a new line between where the numbers end and the letters start:

    The string of letters I need to separate from the numbers only include the letters A, T, C, and G, if that helps. Also, I need to make sure the number stays with the ">NM" or ">NR".

    Any way to do this using sed or any other Linux capable command (doesn't matter which)?

    Thank you.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Look up the sed command: man sed. This will let you do that quite nicely. It is designed to process strings like that - generating output files from input files with string substitution. I use it to generate CSV files from OpenTSDB data for our analytics group. The methodology for what you want is very similar. The substitution string would be something like this: s/N[MR][0-9]*/&\n/
    Try experimenting a bit. Since you only need one pattern match on each line, this should work just fine. In my example I had to match multiple elements on a line, some the same, and others not, so I had to use sed loop constructs. I did that by creating a bash script that wrote a local sed script to the directory where the data needed to go, and piped the data into sed using the temporary script, then deleted the script when done. As I said, your situation is a lot simpler, so you should not need to go to those extremes.

    So, I think you were on the right tracking thinking that sed would work for this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts