Solved Delete first character (1 Viewer)

RevJeff

Registered User.
Local time
Today, 01:10
Joined
Sep 18, 2002
Messages
125
Hello,

Is there a way to delete the first character of every line in a text file?

TIA
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:10
Joined
Sep 21, 2011
Messages
14,310
Read input file line by line
Delete first character
Write remainder to a new file
When at end of file then
Delete input file
Rename output file.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:10
Joined
Feb 28, 2001
Messages
27,190
You could write some VBA in a module you could call that would read the file one line at a time using

Code:
OPEN "inputfilename" FOR INPUT AS FILE #1
OPEN "outputfilename" FOR OUTPUT AS FILE #2
DO UNTIL EOF(1)
    INPUT LINE #1, FILESTRING
    IF LEN( FILESTRING ) = 0 THEN
        PRINT #2
    ELSE
        PRINT #2, RIGHT( FILESTRING, LEN( FILESTRING ) - 1 )
    END IF
    LOOP
CLOSE #1
CLOSE #2

I leave it to you as to getting the input and output names, which can be constants if this is a one-off, or you might need something else if this is going to occur more often. If you want the output file name to match the input filename, you might also need some renaming logic, but again, if this is a one-off then do that part by hand.
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:10
Joined
Sep 21, 2011
Messages
14,310
Now see, I would have used Mid() :)
Amazing how we all think differently. :)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:10
Joined
Feb 28, 2001
Messages
27,190
I'm actually proud of myself for not thinking of something even more obscure, but then again, it's relatively early for me so the "obfuscation" brain cells haven't awakened quite yet.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:10
Joined
May 7, 2009
Messages
19,245
you can also remove it using Notepad++.
Record a macro that delete the first char and goto next line.
save and run the macro until the Eof.

Edit:
There is much better approach, still with Notepad++.
goto the first character of text to delete.
hold Shift-Alt and arrow down to select the first character
of the next line. continue pressing down arrow until all the
first char of all lines are highlighted, press delete.
 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 01:10
Joined
Mar 28, 2020
Messages
1,044
I usually use VIM instead of notepad++ to do that same thing using Visual Block mode. Ctrl-v, then move cursor down to bottom of file and press 'd'.
 

Users who are viewing this thread

Top Bottom