Solved

Changing the path of a column in a text file using batch

Posted on 2014-03-17
1
344 Views
Last Modified: 2014-03-17
Hi,


I want to replace the first column of the text file with another drive location and strip all the subfolders in between. How can I accomplish this in batch?

"\\myserver\sub1\sub2\abc1.pdf","ABC_018-2002-A_0_20011231_20020215__1.pdf","ABCInc","A"


becomes:

"Z:\process\abc1.pdf","ABC_018-2002-A_0_20011231_20020215__1.pdf","ABCInc","A"
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39934899
Try this:
@echo off
setlocal
set SourceFile=D:\Temp\test.txt
set TargetFile=D:\Temp\test-new.txt
set NewFolder=Z:\process
if exist "%TargetFile%" del "%TargetFile%"
echo Processing '%SourceFile%' ...
for /f "tokens=1* delims=," %%a in ('type "%SourceFile%"') do (
	>>"%TargetFile%" echo "%NewFolder%\%%~nxa",%%b
)
echo ... done.

Open in new window

Input and output file location can be passed using the command line or queried for if you prefer that.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
User profile Size Report 3 104
Chocolatey under PowerShell is not working properly 3 94
Batch file to convert a xlsx file to csv 5 361
BatchFile-Disk Detection 23 54
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question