Jump to content

Recommended Posts

Posted

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)

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • hosyn

    14

  • hmsilva

    10

  • BIGAL

    1

Posted
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

Posted

So thanxxxxx hmsilva

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

Posted
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

Posted

Okey test again and everything is okkkkkkkkkkkkkkkkkk

thanxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:):D:)

Posted

You're welcome, hosyn

Glad I could help

 

 

Henrique

Posted

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

Posted

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.

Posted

hmsilva

Everything ok until i wanna change speacial charactor " and parentheses

Posted

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

Posted

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:)

Posted
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

Posted

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:)

Posted
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)

Posted

Try

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

 

HTH

Henrique

Posted

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.

Posted

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

Posted

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 "

Posted

What I was asking was what are you trying to write, a .lsp, or .scr to load all the files in a directory?

Posted

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?

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...