-1

I have a xyz.txt file looking quite like this:

001this is line one
002this is line two
003and this is line three
004and so on

Now I need all those lines as a single txt without the three digit prefix, like:

lineone.txt

this is line one

linetwo.txt

this is line two

And so on. The filenames must not be x(+number).txt. They will all have different names, like content.txt (for line 1) or header.txt (for line 2).

I plan to run this on my Mac with sed or Bash or anything else that works.

  • I plan to run this on may mac with sed or bash or anything else that works. – linda Sep 5 '14 at 17:47
  • 1
    This is really a give us the code question which is not really answered here. I would note though you do not give enough information to solve the problem as what should the output files be named – mmmmmm Sep 5 '14 at 18:48
1

A Perl one-liner that strips all leading digits from every line can be written with the regular expression s/^\d+//g. You can run it like so:

|ruby-2.1.1| cortana in ~/tmp/ad
○ → cat input
001this is line one
002this is line two
003and this is line three
004and so on

|ruby-2.1.1| cortana in ~/tmp/ad
○ → perl -i.bak -pe 's/^\d+//g' input

|ruby-2.1.1| cortana in ~/tmp/ad
○ → cat input
this is line one
this is line two
and this is line three
and so on

|ruby-2.1.1| cortana in ~/tmp/ad
○ → cat input.bak
001this is line one
002this is line two
003and this is line three
004and so on
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .