hosyn Posted July 29, 2014 Share Posted July 29, 2014 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) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 29, 2014 Share Posted July 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 29, 2014 Author Share Posted July 29, 2014 So thanxxxxx hmsilva Item 2 ,3 operate okkkkkkkkk , but item 1 don't act well and no change in "A" , Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 29, 2014 Share Posted July 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 29, 2014 Author Share Posted July 29, 2014 Okey test again and everything is okkkkkkkkkkkkkkkkkk thanxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 29, 2014 Share Posted July 29, 2014 You're welcome, hosyn Glad I could help Henrique Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 29, 2014 Author Share Posted July 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 30, 2014 Share Posted July 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 hmsilva Everything ok until i wanna change speacial charactor " and parentheses Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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 Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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:) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 30, 2014 Share Posted July 30, 2014 hmsilvaEverything 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 Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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?? Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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) Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 30, 2014 Share Posted July 30, 2014 Try (setq x (strcat "(load " (chr 34) "C:/000-lisp1/" x (chr 34) " " (chr 34) "MyLISP Failed to Load" (chr 34)")") HTH Henrique Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 30, 2014 Share Posted July 30, 2014 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 Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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 " Quote Link to comment Share on other sites More sharing options...
hmsilva Posted July 30, 2014 Share Posted July 30, 2014 What I was asking was what are you trying to write, a .lsp, or .scr to load all the files in a directory? Quote Link to comment Share on other sites More sharing options...
hosyn Posted July 30, 2014 Author Share Posted July 30, 2014 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.