Jump to content

Help for lisp routin


hosyn

Recommended Posts

Hi guys i need to rutin that open a file with name test.txt and for each line of this file added

1-find "A" in the file and replace with "AA".
2-added string "xxxxxxxx" in ahead of each line.
3-added "yyyyyy" in the end of each line .

Appriciate for any helping8)

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • hosyn

    14

  • hmsilva

    10

  • BIGAL

    1

Hi guys i need to rutin that open a file with name test.txt and for each line of this file added
1-find "A" in the file and replace with "AA".
2-added string "xxxxxxxx" in ahead of each line.
3-added "yyyyyy" in the end of each line .

One way

(setq a (open "X:\\Your\\Path\\test.txt" "r"))
(while (setq b (read-line a))
 (setq c (cons b c))
);; while
(close a)

(foreach x c
 (if (wcmatch x "*A*")
   (progn
     (setq i 0)
     (while (setq i (vl-string-search "A" x i))
(setq x (vl-string-subst "AA" "A" x i))
(setq i (+ i 2))
     );; while
   );; progn
 );; if
 (setq	x (strcat "xxxxxxxx" x "yyyyyy")
d (cons x d)
 );; setq
);; foreach

(setq a (open "X:\\Your\\Path\\test.txt" "w"))
(foreach x d
 (write-line x a)
);; foreach
(close a)

Hope that helps

Henrique

Link to comment
Share on other sites

So thanxxxxx hmsilva

Item 2 ,3 operate okkkkkkkkk , but item 1 don't act well and no change in "A" ,:?

 

 

Are you sure?

with

A test e test AA A A

testing B A

Testing A B and C

after running the code

xxxxxxxxAA test e test AAAA AA AAyyyyyy

xxxxxxxxtesting B AAyyyyyy

xxxxxxxxTesting AA B and Cyyyyyy

 

 

Henrique

Link to comment
Share on other sites

And if i have this dos command in bat file ,is there any way for changing to lisp rotine?///?

dir/b/oN/A-H    *.LSP >uu(LSP).LSP

Link to comment
Share on other sites

Search here for these two lisp commands Getfiled and Findfile you will find examples to do what you want, as I understand you want .lsp A-H you may need to strip down a list as the two methods I think will give you all but thats easy look at fisrt character of filename.

Link to comment
Share on other sites

hmsilva

Everything ok until i wanna change special characters " and parentheses

at this case lisp mismatch:?

(foreach x c

 (setq	x (strcat "[u](load "C:\\000-lisp1\\[/u]" x "[u] " "MyLISP Failed to Load")[/u]")
d (cons x d)
 );; setq
);; foreach

Link to comment
Share on other sites

Hi Bigal

I tried following command for dir ::

(command "dir" " C:\\000-lisp--3-1   /b/oN/A-H    *.LSP > C:\\000-lisp--3-1\\uu(LSP).txt")

but didn't operate wello:)

Link to comment
Share on other sites

hmsilva

Everything ok until i wanna change special characters " and parentheses

at this case lisp mismatch:?

(foreach x c

 (setq	x (strcat "[u](load "C:\\000-lisp1\\[/u]" x "[u] " "MyLISP Failed to Load")[/u]")
d (cons x d)
 );; setq
);; foreach

 

Try

(setq x (strcat "(load " (chr 34) "C:\\000-lisp1\\"  x (chr 34) " " (chr 34) "MyLISP Failed to Load" (chr 34)")")

 

Henrique

Link to comment
Share on other sites

HI BIGAL

I tried this:

(command "dir" " C:\\000-lisp-93-3-1   /b/oN/A-H    *.LSP > C:\\000-lisp-93-3-1\\uu(LSP).txt")

but didnt do well ,any problem in this code??o:)

Link to comment
Share on other sites

Try

(setq x (strcat "(load " (chr 34) "C:\\000-lisp1\\"  x (chr 34) " " (chr 34) "MyLISP Failed to Load" (chr 34)")")

 

Henrique

 

I cheked routine but unfortunatelly didn't do well , and your modification that's mean i must replace internal " with (chr 34)

Link to comment
Share on other sites

Try

(setq	x (strcat "(load " (chr 34) "C:/000-lisp1/"  x (chr 34) " " (chr 34) "MyLISP Failed to Load" (chr 34)")")

 

HTH

Henrique

Link to comment
Share on other sites

hmsilva

I tried but had problem still..at this time i divided routin to two separate opretion :

1- i change [color="olive"]"[/color] to www string character .
2-now code change to ::  (setq	x (strcat "(load WWWC:\\000-lisp-93-3-1\\"   x   " WWW WWWMyLISP Failed to LoadWWW)")
3-and operate the fierst lisp
4-the second lisp for replacing  WWW--->> "  and  \ ----->> \\

Now everything ok until item 3 and i need the lisp code for find and replacing www and \ in the file after that running sequential lisp 1 and 2.

Link to comment
Share on other sites

Now, I'm getting puzzled...

 

 

Can you explain what you're trying to do.

Why you need the WWW and then modify it to " ?

 

 

Henrique

Link to comment
Share on other sites

BECOUSE OF TRIED:

(setq	x (strcat "(load " (chr 34) "C:/000-lisp1/"  x (chr 34) " " (chr 34) "MyLISP Failed to Load" (chr 34)")")

AND DIDN'T DO WELL.

So for getting modular two task i divide it two section:

1-one lisp for prefix and suffix

2-another one find and replacing

i tried above (withchanging " to www) and everything was ok.

 

When lisp mismatch with several " i change internal " to www after added prefix and suffix for each line i change back again from www to "

Link to comment
Share on other sites

a .lsp

 

Indeed my idea :

i have lisp files in specific directory and every time i added new lisp file for testing to them

i have a bat file for getting the name of these files to one file with :

(command "dir" " /b/oN/A-H    *.LSP >uu(LSP).LSP")

after that with this routine i chang each line to

(load "C:\\lsp--------hlsp\\80----DynOff---DIN OFFSET-----DynOffV2-1.lsp" "MyLISP Failed to Load")
(load "C:\\lsp--------hlsp\\80----trim.lsp" "MyLISP Failed to Load")
(load "C:\\lsp--------hlsp\\80----ctyu.lsp" "MyLISP Failed to Load")
and more file here..........................

and with one command every file embed in the directory load auto to cad:)

are there better way for do this?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...