Search code examples
batch-filebatch-processing

How to delete the first “text” the each line of the text


This is the first time I’m asking question there so I’m sorry if is there anything I did wrong

Consider a file names '00.txt' and It contains the following.

ai_00_01_01 word01 word01(translated)
ai_00_01_02 word02 word02(translated)

...
ai_00_01_305 word305 word305(translated)

P.S. (translated) doesn’t mean there is really a () there, it is just a other language of that line’s word

I hope it changed to this :

word01 = word01(translated)
word02 = word02(translated)

...
word305 = word305(translated)

The things I tried:

cut -f 2- -d ' ' 00.txt > new_file.txt

"Give me the second and any other field beyond, using space as a delimiter, from the file.txt file and direct the output to new_file.txt" -by ivanivan in https://unix.stackexchange.com/questions/515249/how-to-delete-the-first-word-in-each-line-of-a-file (I think it’s means it is delete the text until the first space?Bad English sorry)

The code I tried just generate a new txt file while nth inside, and the 00 txt file didn’t change anything

Thanks to anyone to help this noob(aka myself)


Solution

  • Since your data is already separated by spaces, you can use a for /f loop with the default delimiters:

    for /f "tokens=2,3" %%A in (00.txt) do echo %%A = %%B >>new_file.txt
    

    This takes the second and third thing in each line, stores the second thing in %%A and the third thing in %%B, and then displays those two things in the format you mention in your question, redirecting it to new_file.txt. (Note that if you think you'll run the script more than once, you should add a line before this to delete new_file.txt or else you'll just append the lines to the end of the existing file.)