Como sacar los números?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Como sacar los números?

#1 Post by macoga » 27 Aug 2023 16:05

Hola a todos, estuve alejado un tiempo por salud. ahora buscando un codigo CMD para eliminar numeros de una lista de texto desde el 1 al 999, por ejemplo: 1-amigos, 99-familia, 300-direcciones. Que solo queden las palabras.

Gracias de antemano y un saludo a todos

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Como sacar los números?

#2 Post by Aacini » 27 Aug 2023 19:22

Lo primero que debes saber es que éste es un sitio en inglés. Debes traducir tus preguntas usando cualquier traductor (por ejemplo, pon en la barra de Google: "significado de english en español").

Las preguntas deben ser claras. Aunque tu pregunta es lo bastante sencilla para entenderla, deberías poner un ejemplo de los archivos de entrada y salida que deseas.

Este archivo Batch hace lo que pides:

Code: Select all

@echo off

(for /F "tokens=1* delims=-" %%a in (entrada.txt) do echo %%b) > salida.txt
También puedes teclear directamente ese comando en la línea de comandos de esta manera:

Code: Select all

(for /F "tokens=1* delims=-" %a in (entrada.txt) do @echo %b) > salida.txt
Lo que sigue es la traducción al inglés de mi respuesta que obtuve de la manera que dije antes.

-------------------------------------------------------------

The first thing you should know is that this is an English site. You must translate your questions using any translator (for example, put in the Google toolbar: "english meaning in spanish").

The questions must be clear. Although your question is simple enough to understand, you should give an example of the input and output files you want.

This Batch file does what you ask:

Code: Select all

. . .
What follows is the English translation of my answer that I got the way I said before.


Antonio

macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Re: Como sacar los números?

#3 Post by macoga » 28 Aug 2023 08:13

Hello everyone, I was away for a while for health reasons. I am now looking for a CMD code to remove numbers from a text list that I have in a folder.
The list have a bunch of txt files from 1 to 999,
for example:

1-friends
20-recipes
99-family
300-addresses

So, I need to take the number and the dash off to end up like this:

friends
recipes
family
addresses

Thanks Aacini, for the translation tip, and cmd code, I was trying a vbs code and didn´t work.

macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Re: Take Numbers off a list?

#4 Post by macoga » 28 Aug 2023 08:33

I guess didn´t explain my first question right, Aacini. Sorry!!!!

I did the translation as you show me,thanks.

I have a folder with hundreds of txt files, and they are number as I said before, I need a code where I can put the path to that folder, then take the numbers off.

I really thanks you Aacini

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Como sacar los números?

#5 Post by Batcher » 28 Aug 2023 08:47

test.bat

Code: Select all

@echo off
cd /d "%~dp0"
for /f "tokens=1* delims=-" %%i in ('dir /b /a-d *.txt ^| findstr /b "[0-9][0-9]*-"') do (
    ren "%%i-%%j" "%%j"
)

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Como sacar los números?

#6 Post by Aacini » 29 Aug 2023 18:36

macoga wrote:
28 Aug 2023 08:13
Hello everyone, I was away for a while for health reasons. I am now looking for a CMD code to remove numbers from a text list that I have in a folder.
The list have a bunch of txt files from 1 to 999,
for example:

1-friends
20-recipes
99-family
300-addresses

So, I need to take the number and the dash off to end up like this:

friends
recipes
family
addresses

Thanks Aacini, for the translation tip, and cmd code, I was trying a vbs code and didn´t work.
Hey! You altered your original question when you translated it! :shock:

This is your original question, translated to English:
Hello everyone, I was away for a while for health. now looking for a CMD code to remove numbers from a text list from 1 to 999, for example: 1-friends, 99-family, 300-addresses. Let only the words remain.
In your altered question you added "in a folder" and "The list have a bunch of txt files". In this new question it is obvious that you have several files, but in your original question you suggested that you have "a text list", in one file! :?

macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Re: Como sacar los números?

#7 Post by macoga » 31 Aug 2023 18:45

You are right Aacini, and my apologies, but when I translated it I thought more about the question, and yes the text files are inside a folder, so the code needs a path to it, and then a command to get rid off the left digits up to the dash (-)

macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Re: Como sacar los números?

#8 Post by macoga » 31 Aug 2023 18:50

The same apologies to Batcher, as he also send a code just for a list.

Batcher
Posts: 74
Joined: 16 Apr 2009 10:36

Re: Como sacar los números?

#9 Post by Batcher » 31 Aug 2023 21:20

test-2.bat

Code: Select all

@echo off
cd /d "path/to/your/folder"
for /f "tokens=1* delims=-" %%i in ('dir /b /a-d *.txt ^| findstr /b "[0-9][0-9]*-"') do (
    ren "%%i-%%j" "%%j"
)

macoga
Posts: 20
Joined: 03 Oct 2021 09:35

Re: Como sacar los números?

#10 Post by macoga » 30 Sep 2023 16:31

Beautifully done, thanks Batcher, works great

I should change the title of the request to English

Post Reply