1

This is the input file:-

Hello,1-23456
How are you,2-34567
.
.
.

I want output:-

1-23456,Hello
2-34567,How are you
.
.
.

Please help me to create a batch file for this.

I have tried this

@echo off &setlocal

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%i in (%textfile%) do set srno=%%a&set comments=%%b (
    set "line=%%i"
    setlocal enabledelayedexpansion
set "line=%comments%,%srno%"
    echo(!line!
    endlocal
))>>"%newfile%"

But i am not getting the desired output

2
  • 2
    What have you tried? Please attempt to solve your own questions before asking them here, and add what you have come up with to your question. Commented Mar 6, 2016 at 7:53
  • I have attempted to this problem, please take a look and help me Commented Mar 6, 2016 at 10:26

1 Answer 1

0
@echo off &setlocal

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%a in (%textfile%) do (
    echo %%b,%%a"
))>>"%newfile%"

Edit to match additional requirement from comment:

you need delayed expansion and to escape the special character "|"

@echo off 
setlocal enabledelayedexpansion

set "textfile=inputchq.csv"
set "newfile=output.txt"

(for /f "tokens=1,2 delims=," %%a in (%textfile%) do (
    set "line=%%b,%%a"
    echo !line:^|=.!
))>>%newfile%
Sign up to request clarification or add additional context in comments.

1 Comment

In this same solution i want to replace all "|" with "." where can i add in this loop.Please help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.