cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Command Line Program in a mapkey

STEVEG
21-Topaz I

Command Line Program in a mapkey

Does anyone know how, in a command prompt, to remove the last character in each line of a .txt file?

I need to open a family table instance, do one operation, close that instance then open the next instance and do the same thing.  And so on.

I am combining a mapkey with a batch file and I am close.  But I have to remove the last character in each line and I can't figure out how.


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
ACCEPTED SOLUTION

Accepted Solutions
JLG
1-Newbie
1-Newbie
(To:STEVEG)

I saved each page out as an .mht file; hopefully you can read them.

View solution in original post

9 REPLIES 9
MartinHanak
24-Ruby III
(To:STEVEG)

Steve,

you can do following (for example):

1.] install sed (stream editor) ... available at sed for Windows

2.] use command prompt command ... sed "s/.$//" a.txt > b.txt

a.txt ... source file

b.txt ... removed last character in each line

MH


Martin Hanák
Chris3
21-Topaz I
(To:STEVEG)

You don't have to install external sfotware. You might be able to do this with a batch, but vbs has a little more utility. In your config.pro, just change the .bat to .vbs and use the code below (with modifications as required)

Set objFS = CreateObject("Scripting.FileSystemObject")

strFile = "c:\test\file.txt"

strTemp = "c:\test\temp.txt"

Set objFile = objFS.OpenTextFile(strFile)

Set objOutFile = objFS.CreateTextFile(strTemp,True)   

Do Until objFile.AtEndOfStream

    strLine = objFile.ReadLine

    ' Remove last character from strLine

     'This removes the carriage return and the last character and then adds the carriage return back

     strFile = Left(strFile, Len(strLine) - 2) & vbCrLf

    objOutFile.Write(strLine)

Loop

objOutFile.Close

objFile.Close

objFS.DeleteFile(strFile)

objFS.MoveFile strTemp,strFile

STEVEG
21-Topaz I
(To:STEVEG)

Martin,

should have mentioned I can't install external software not approved by out IT dept.  But thank you for it.

Chris,

Thank you for the suggestion.  I might try that but I'd prefer straight command line commands.

JLG
1-Newbie
1-Newbie
(To:STEVEG)
STEVEG
21-Topaz I
(To:JLG)

Unfortunately I do not have access to some sites from work.  Stack Overflow is one of them.

JLG
1-Newbie
1-Newbie
(To:STEVEG)

I saved each page out as an .mht file; hopefully you can read them.

STEVEG
21-Topaz I
(To:JLG)

That's awesome.  Thank you for uploading the pages.

Unforturnately, it doesn't look like it will work.  The for command doesn't like the tilde character.  I can do it outside the for command but that won't help.  And using what they suggested doesn't output the line.

STEVEG
21-Topaz I
(To:STEVEG)

I DID IT!

I tried many different variations of what was on those pages.  But I never tried the example where they used the CALL command.  This is what worked.  Or at least seems to have worked.  I'l know once I get the mapkey and batch file all set.

Thank you so much.

SETLOCAL
for /f "delims=" %%a in (abc.pro) do (
set str=%%a
CALL :remove "%str%"
)
goto EOF


:remove
set str=%str:~0,-3%
echo %str% >> def.pro

:EOF

STEVEG
21-Topaz I
(To:STEVEG)

And just a little more information.

I also got a space at the end with this code.  It's easy to remove that actually.  I did some searching and found the answer.

Remove the spaces between the ">>" in the line echo %str% >> def.pro.  That space adds the space at the end of the line in def.pro.

So now it's:

echo %str%>>def.pro

Announcements
NEW Creo+ Topics: PTC Control Center and Creo+ Portal


Top Tags