Solved

How to automatically edit a text file to add a command space and then move the below line up to after the space

Posted on 2011-03-11
7
258 Views
Last Modified: 2012-05-11
We use a scanner to scan bar codes when we get in inventory. The Inventory system is web bases so all we have to do is type in that number into a text box or several numbers and it will update the file with all the item. The problem is that the scanner outputs the serial numbers like this (below)

00020957000311
00020957000311
16139651541515
etc

When we put them into the browser to do it to enter multiple items we have to change it to

00020957000311, 00020957000311, 16139651541515...etc

Basically we have to take the list and hit comma space delete so they line up like that so the S/W can upload multiple serial numbers. The problem is this list can be 500 serial numbers long and ir rather tedious. Is there any sort of script or Macro that can do this from the list?
 
0
Comment
Question by:Axis52401
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35113307
by hand, you can put your numbers in column A, put this in B1 =A1, and in B2 put =B1&","&a2 and copy down b2 all the way down. The last B will be the result you need.

Thomas
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35113320
By macro, you can put your numbers in column A and run the attached code

sub concat
dim cl as range, strResult as string

for each cl in range(cells(1,1),cells(rows.count,1).end(xlup))
strresult=strresult & cl &","
next cl

strresult=left(strresult,len(strresult)-1)

cells(1,2)=strresult

end sub

Open in new window

0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 35113670
If you want to do it in a BAt script, you can do the following:

@echo off
if exist "c:\temp\output.txt" del "c:\temp\output.txt"
for /F "tokens=*" %%A in ("c:\temp\input.txt") do (
  echo.%%~A>>"c:\temp\output.txt"
)

Open in new window

~bp
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Axis52401
ID: 35116143
I was hoping there was some sort of Utility I could use, I'm bot much of a programer.

Thanks
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 35117283
Assuming you have those serials in a plain text file, try the batch script below. Save it as Whatever.cmd, then simply use Explorer to drag the serial text file on the batch script. It will create a new file with the same name as the serial file, but the extension ".out" (you can change that in line 4 if you want to). It will then open the new file in notepad, so you can copy and paste it from there.
@echo off
setlocal enabledelayedexpansion
set InFile=%~1
set OutFile=%~dpn1.out
if exist "%OutFile%" del "%OutFile%"
set Delim=
for /f "tokens=*" %%a in ('type "%InFile%"') do (
  (<NUL set /p Dummy=!Delim!%%~a)>>"%OutFile%"
  set "Delim=, "
)
start "" notepad.exe "%OutFile%"

Open in new window


billprew,
sorry, but that script won't work. To start with, it will only process the string "c:\temp\input.txt", not the file content, and even with that corrected, it will create another file with one serial per line, not one long line with comma separated serials.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 35118087
oBda, wow, I was dozing when I created that, wasn't I !
0
 
LVL 2

Author Closing Comment

by:Axis52401
ID: 35172767
Thanks, that worked perfectly
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

730 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