?
Solved

Removing path and quotes in batch

Posted on 2014-03-22
3
Medium Priority
?
305 Views
Last Modified: 2014-04-01
Hi

   I am looking to process a txt file that has the following format and get a new text file of the new format, also listed below. In essence, the batch would need to remove all drive and folders and unquote the first entry. Please help me with writing the batch code to do it.

Input file:
"Z:\B\1.pdf","newfile1.pdf",<mystring>,<mystring>

Would like:

1.pdf

Thanks
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
  • 2
3 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39948264
Don't know in batch, in PS you can do it like this:
$inputText = "`"Z:\B\1.pdf`",`"newfile1.pdf`",<mystring>,<mystring>"
$outputText = $inputText.Split("`"")[1] # get only the file name, with path
$outputText = $outputText.Split("\")[-1] # get only the file name
echo $outputText

Open in new window

HTH,
Dan
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 39948311
@echo off
(for /f "tokens=1 delims=," %%a in (oldfile.csv) do echo %%~nxa) >newfile.csv

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39948313
That means take the first part of the line upto the comma in file oldfile.csv and for each entry the ~ strips the quotes, and "nx" leaves the Name and eXtension of the filename only.  Whole lot redirected into one file, or you can do other processing in the loop rather than creating a new file.

Steve
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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