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
254 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 53

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 83

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 53

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
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…

776 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