How can I extract text before a character or string in a batch file?

Mark Deven

I'm basically looking for the opposate of this post: https://stackoverflow.com/questions/47796707/how-to-extract-text-after-in-batch-file. I'm looking to extract the text before an equal sign in a string of text (or remove the text after the equal sign and the equal sign).

Example Input:

User=Your Friend

Desired Output:

User

Since the length of the text before and after the equal sign varies I cant use something like %var:~0,-12%.

DavidPostill

I'm looking to extract the text before an equal sign in a string of text

Use the following batch file (test.cmd):

@echo off
setlocal enabledelayedexpansion
set _string=User=Your Friend
echo %_string%
for /f "tokens=1 delims==" %%a in ("%_string%") do (
  echo %%a
  )
endlocal

Example output:

> test
User=Your Friend
User

Further Reading

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I call a batch file within another batch file?

분류에서Dev

How can i compare string and character types?

분류에서Dev

How can I extract text between parentheses containing a specific word?

분류에서Dev

How can I copy a text file into another?

분류에서Dev

how can I remove white space in a string and replace it with (;) in batch

분류에서Dev

How can i resolve the path laocation in batch file

분류에서Dev

How can I run a batch file with a loop as a scheduled task?

분류에서Dev

How can I get a character of a string at a particular index?

분류에서Dev

How can I extract all links (href) in an HTML file?

분류에서Dev

what can I use sed to search for a string and append /sub1 and some file ../ before search string

분류에서Dev

How I can I start a powershell command line from a batch file and enforce it to stay open?

분류에서Dev

Batch file - file name extract

분류에서Dev

How can I find all files that do NOT contain a text string?

분류에서Dev

How can I get a part of text file by terminal

분류에서Dev

how can I read from an uploaded text file

분류에서Dev

How can I run a specific line as a command in a text file?

분류에서Dev

How can I remove text on the last line of a file?

분류에서Dev

I want to write a batch file that internally calls python script and I want python script to return some value to the batch file. how can I do that?

분류에서Dev

How can i add a string to the beginning of every line in a file with sed?

분류에서Dev

How can I pass command line arguments to a program in a Windows batch file?

분류에서Dev

php How can I replace a character in a string (only) when it is in a certain place?

분류에서Dev

How can I check in Apex if a batch is scheduled?

분류에서Dev

Using Perl, how can I extract from a log file only the errors that happened during a specific minute?

분류에서Dev

In Python, how to write strings in a file in a loop and before the loop stops, I can get the results runtimely?

분류에서Dev

How can I display text from a file automatically after powering up my computer, in text editor or terminal?

분류에서Dev

How can I read a text file from the terminal and save the output to another file in java?

분류에서Dev

Can I recover this corrupted text file

분류에서Dev

How to create new command to execute a batch file with Sublime Text?

분류에서Dev

Remove All Character before a String and the String itself

Related 관련 기사

  1. 1

    How can I call a batch file within another batch file?

  2. 2

    How can i compare string and character types?

  3. 3

    How can I extract text between parentheses containing a specific word?

  4. 4

    How can I copy a text file into another?

  5. 5

    how can I remove white space in a string and replace it with (;) in batch

  6. 6

    How can i resolve the path laocation in batch file

  7. 7

    How can I run a batch file with a loop as a scheduled task?

  8. 8

    How can I get a character of a string at a particular index?

  9. 9

    How can I extract all links (href) in an HTML file?

  10. 10

    what can I use sed to search for a string and append /sub1 and some file ../ before search string

  11. 11

    How I can I start a powershell command line from a batch file and enforce it to stay open?

  12. 12

    Batch file - file name extract

  13. 13

    How can I find all files that do NOT contain a text string?

  14. 14

    How can I get a part of text file by terminal

  15. 15

    how can I read from an uploaded text file

  16. 16

    How can I run a specific line as a command in a text file?

  17. 17

    How can I remove text on the last line of a file?

  18. 18

    I want to write a batch file that internally calls python script and I want python script to return some value to the batch file. how can I do that?

  19. 19

    How can i add a string to the beginning of every line in a file with sed?

  20. 20

    How can I pass command line arguments to a program in a Windows batch file?

  21. 21

    php How can I replace a character in a string (only) when it is in a certain place?

  22. 22

    How can I check in Apex if a batch is scheduled?

  23. 23

    Using Perl, how can I extract from a log file only the errors that happened during a specific minute?

  24. 24

    In Python, how to write strings in a file in a loop and before the loop stops, I can get the results runtimely?

  25. 25

    How can I display text from a file automatically after powering up my computer, in text editor or terminal?

  26. 26

    How can I read a text file from the terminal and save the output to another file in java?

  27. 27

    Can I recover this corrupted text file

  28. 28

    How to create new command to execute a batch file with Sublime Text?

  29. 29

    Remove All Character before a String and the String itself

뜨겁다태그

보관