4

I have a text file where I want to remove the first 6 characters of every line. The characters are whitespace and some numbers. They are ascii characters. How can this be done? I have a windows environment.

Example file:

54863 important text line 1
14247 important text line 2
29751 important text line 3

Example result:

important text line 1
important text line 2
important text line 3
finefoot
  • 9,914
  • 7
  • 59
  • 102
wolfgang mrazek
  • 51
  • 1
  • 1
  • 3
  • You can do it by most programming languages and most text editors. What do you have in your tool box? – chance Dec 13 '11 at 13:11
  • You really need to clarify how you want to do this programmatically. If not, you can try asking on superuser.com, but be sure to provide a bit more detail if you do. – Tim Post Dec 13 '11 at 13:21
  • This can also be done using [GNU `sed`](https://www.gnu.org/software/sed/manual/sed.txt) for this: `cat input.txt | sed 's/^......//' >output.txt`. Here, `^......` means 6 arbitrary characters at the beginning of a line. So if you need to replace only 4 characters you would use `sed 's/^....//'` and so on. If you are on Windows, you can [download a port of `sed` here](http://gnuwin32.sourceforge.net/packages/sed.htm), for example, or have a look at [this question](https://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe) for further options. – finefoot Jun 11 '18 at 12:39

3 Answers3

8

You could do this in any text-editor that supports regular expressions (notepad++ is windows and its free)

A simple expression for find and replace would be

^......

Which would match the first six character of each line. Obviously you can replace with "" nothing.

Fraser
  • 15,275
  • 8
  • 53
  • 104
  • This should be marked as suggested solution. It has saved the day for me. Other answers with column selection are OK but works for rather smaller files. When you have file with i.e. 200 000 lines, you would struggle. Regular expression approach is much more generic and way faster. – Wojciech Jakubas Jan 04 '19 at 12:25
  • You're a genius. – Scadge Feb 05 '19 at 09:46
  • 2
    Use the following expression to specify the number of characters: `^.{n}`. Replace "n" with a number like 87. Less work if you need to remove a lot of characters. – Markus Feb 28 '20 at 15:30
2

Grab yourself Notepad++ (e.g. from www.portableapps.com), make a rectangular selection over the first six characters end press DEL. To make a rectangular selection hold ALT and drag with left mouse button clicked.

Ocaso Protal
  • 19,362
  • 8
  • 76
  • 83
0

If you only need to do this once, open your file in a text editor that supports column selection, select the columns you want to cut, and delete them. For example, Notepad++ enters column selection mode when you press ctrl + alt.

If you want to do this more than once, you should write a script that would do it for you. Can you program in any language?

socha23
  • 10,171
  • 2
  • 28
  • 25