![]() |
How do i read particular text from text file and update those values in MS SQL table - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How do i read particular text from text file and update those values in MS SQL table (/thread-14119.html) |
RE: How do i read particular text from text file and update those values in MS SQL table - buran - Nov-16-2018 Line that is processed is specified in this row line = my_file.split('\n')[6]That is line 7 from the text file (index is 0-based). That said you should really start doing your work and not asking us to do/explain every single step of it. the code I provided is more or less self explanatory. I merged your other thread into this one and it's original post disappeared. I hope there was no important info that is missing now? RE: How do i read particular text from text file and update those values in MS SQL table - ganeshsai2912 - Nov-16-2018 Thanks for your information. The code is perfectly working except specific text in different line. if i get that specific portion code, my problem solved and i will close the issue. like that, i have many requirements which i will do it myself further. Note : merging other thread is entirely different. RE: How do i read particular text from text file and update those values in MS SQL table - buran - Nov-16-2018 OK, I show you how to read specific line, do the same (with some changes) with the other line you want I split again the other thread - https://python-forum.io/Thread-split-How-do-i-read-particular-text-from-scanned-documents RE: How do i read particular text from text file and update those values in MS SQL table - ganeshsai2912 - Nov-16-2018 not clear.. RE: How do i read particular text from text file and update those values in MS SQL table - buran - Nov-16-2018 (Nov-16-2018, 07:26 AM)ganeshsai2912 Wrote: not clear..what is not clear? I showed how to access line by index. I showed how to parse a line (of course other approaches are possible too). I just have to do it for another line. If it's not up to you skills, then maybe you should not take work for clients that you cannot deliver RE: How do i read particular text from text file and update those values in MS SQL table - ganeshsai2912 - Nov-16-2018 can you give me clue..?..how to access line by index RE: How do i read particular text from text file and update those values in MS SQL table - buran - Nov-16-2018 (Nov-16-2018, 05:34 AM)buran Wrote: Line that is processed is specified in this row unable to read specific text from text file using python - ganeshsai2912 - Nov-16-2018 I writing python program which read specific text from text file. The program is working fine if it is static line index. if it is dynamic search in the whole document, i am unable to read.. particularly, i want to get "Join Date","Relieve Date",etc. along with 3 main parameter(EmpNo,Name,Salary). How to change the below code..? import glob def parse_line(line): for item in ['Emp No', 'Name', 'SAL', 'Join Date']: line = line.replace(item, '') return [item.strip() for item in line.split(':') if item.strip()] def process_file(file_name): with open(file_name) as f: line = f.readlines()[6] print(line) return parse_line(line) pattern = 'C:/Test/Python/Project/*.txt' files = glob.glob(pattern) all_data = [process_file(file_name) for file_name in files]sample text file attached in the below link. final out put would be EmpNo: 101 Name: RASUL L SAL: 30000 JoinDate :XXXXX Sample file attached. Sample file attached RE: How do i read particular text from text file and update those values in MS SQL table - buran - Nov-16-2018 Please, don't start new threads. Keep the discussion in this thread. It's really frustrating when people don't want to put any effort and expect others to do their work. I showed several times how to access line by index. The EmpNo, Name, and SAL are on line 7 (i.e. index = 6). Join date is on line 9, i.e. index=8. I also showed you how to parse the line and get separate elements. Just amend the code to do the same for line 9 RE: How do i read particular text from text file and update those values in MS SQL table - ganeshsai2912 - Nov-16-2018 I tried some code's. but, no luck and i am struggling. I have no idea how to proceed further..? Note : Mention index which we need to hard code or loop it...? |