I have this txt file which is ls-r directory in linux system. Example file:
etc.: ArchiveSEL xinetd.d etc / cmm: CMM_5085.bin cmm_sel storage. Cfg etc. / crontabs: root etc / pam.d: ftp rsh etc / rc.d: eth .set.sh rc.sysinit etc / rc.d / init.d: cmm functions usernap etc. / security: access.conf Console.apps time.conf etc / security / console.apps: kbdrate etc / ssh: ssh_host_dsa_key sshd_config etc. / var: setUser snmpd.conf etc / xinetd.d: irsh wu-ftpd I would like to divide it into several files by subdirectory. Example files will be like this: etc. etc etc. CMTTPTT, Adikantabest, etc. PAMD TTT, can anyone give me a Python code that can do this? Note that the sub-directory line ends with ':', but I am not smart enough to write the code. Some examples would be appreciated thanks :)
Maybe something like this? Again M generates a multi-line regular expression that can match multiple lines, and the last part just overrides on matches and creates files ...
import Re-Data = '& lt; As your input data & gt; # Or open ('data.txt') Read () result = map (Lambda M: (m [0], m [1] .stip (). SplitLines ()), re.fandol ('^ ([^ \ N] +): \ n ((?: [^ \ N] + \ n) *) \ n ', data, again .m files for the result: f = open (dirname.replace (' lines in files / ',' ''). Txt ',' w '): f.write (line +' \ n ') f.close ()
Comments
Post a Comment