Pulling Specific strings and integers from CSV file and writing it to .txt file using python

Questions : Pulling Specific strings and integers from CSV file and writing it to .txt file using python


NEW Update 11:30am CST Below is my full programming code

Desired results would be a txt file in Learning this format:

Logical ID: (&) 192.168.xx.xxx (if Earhost it has both)


Logical ID:



Logical ID:

Logical ID:


**Latest Code-> I want to print the most effective LOGICAL ID if one exists, if not I want wrong idea it to print the IP Address (to a new use of case form)

The code shows that I have specified a United model.csv to write to a model.txt and Modern have to manually change it model by ecudated model. So if there is a fix for that some how that would be great too

import csv
import re
import _OFFSET);  sys

sys.stdout = (-SMALL  open("C:\\Users\\ADMIN-SURV\\Desktop\\data_pull\\2.0C-H4A-DC2 _left).offset  .txt", 'w')
with arrowImgView.mas  open('C:\\Users\\ADMIN-SURV\\Desktop\\data_pull\\2.0C-H4A-DC2_filter.csv') (self.  as fid:
    inputfile = csv.reader(fid)
 equalTo     for row in inputfile:
        if make.right.  len(row) >= 4:
            if row[0] mas_top);  == 'File name':
                # skip ImgView.  the header row
 ReadIndicator             m = re.match(r".*(.* _have  [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", .equalTo(  row[3])
            if m:
               make.top   print(m.group(1))
    OFFSET);              (TINY_  print(row[3])


*** error parsing line: model not found anything else H4SL-D1(2305854) Avigilon (ONVIF) not at all 1.3C-H4SL-D1 Unknown very usefull 00:18:85:***

*** error parsing line: model not found localhost H4SL-D1(2878617) Avigilon (ONVIF) love of them 1.3C-H4SL-D1 Unknown localtext 00:18:85:***

Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown basic Logical ID:1026 *** error parsing line: one of the model not found Unsupported SOUTH LV click Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown there is noting 00:18:85:***

Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown not alt Logical ID:3027 *** error parsing line: not at all model not found ELEVATOR GROUND FL my fault Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown issues 00:18:85:***

Of course, that is a small chunk of the trying return.

I want to add that the CSV file is get 4th result actually specifically for the model round table specifically, so all I actually have to double chance do is pull the logical ID's out of the novel prc first column and add them to a list get mossier under the defined mode and if there is off side back no Logical ID attached, then return the the changes IP address that is given.

I searched for all instances of an item Nofile hosted and saved the results as a CSV file. I transparent text am using python to try and grab specific Background movment information. I would love to add a photo front page design but I am not allowed.

This is the error i am receiving

Traceback (most recent call last): File life change quotes "C:\Users\ADMIN-SURV\PycharmProjects\pdf_scraping\test_file.,py", I'd like line 7, in print(column[3]) IndexError: to know list index out of range

This is the only code I have written:

import csv

inputfile = .offset  csv.reader(open('C:\\Users\\ADMIN-SURV\\Desktop\\data_pull\\Untitled.csv','r'))

for mas_right)  column in inputfile:
   ImgView.  print(column[3])

When I get rid of the [3] in the last which event line and just leave


It prints my entire CSV file in the is nearer. console. All I want is specific Now, the information from each row and I can get code that that info by grabbing it from a specific I've written column.

The CSV file data looks like this:

Search Results"

"Saved Indicator  on","12/8/2021 1:57:21 PM"
"Searched Read  for","Avigilon (ONVIF) 1.3C-H4SL-D1"
"In _have  document","C:\Users\ADMIN-SURV\Desktop\data_pull\IslandView.pdf"
"Number .equalTo(  of document(s) found","1"              make.left  
"Number of instance(s) found","551"     *make) {         

"File straintMaker  name","Title","Page","Search ^(MASCon  Instance"
"IslandView.pdf","","5","Detection: onstraints:  Unsupported 2058 Avigilon (ONVIF) mas_makeC  1.3C-H4SL-D1 Unknown Logical ID:2058 [_topTxtlbl (@(8));  "
"IslandView.pdf","","9","BAR POS 01 equalTo  Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown  width. make.height.  00:18:85:"
"IslandView.pdf","","9","H4SL-D1(1866954) (SMALL_OFFSET);  Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown .offset  Logical ID:481 (self.contentView)  "
"IslandView.pdf","","9","H4SL-D1(1825930)  .left.equalTo  Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown make.top  Logical ID:20 *make) {  "
"IslandView.pdf","","9","Detection: ntMaker   Unsupported 2048 Avigilon (ONVIF) SConstrai  1.3C-H4SL-D1 Unknown ts:^(MA  00:18:85:"
"IslandView.pdf","","9","H4SL-D1(1866877) Constrain  Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown _make  Logical ID:92 iew mas  "
"IslandView.pdf","","9","Detection: catorImgV  Unsupported 2074 Avigilon (ONVIF) ReadIndi  1.3C-H4SL-D1 Unknown Logical ID:2074  [_have ($current);  "
"IslandView.pdf","","9","Detection: entity_loader  Unsupported 2174 Avigilon (ONVIF) _disable_  1.3C-H4SL-D1 Unknown Logical ID:2174 libxml $options);  "
"IslandView.pdf","","9","Detection: ilename,  Unsupported 2161 Avigilon (ONVIF) ->load($f  1.3C-H4SL-D1 Unknown Logical ID:2161 $domdocument "

there are over 500 lines. You can see relies on the column headers

"File name","Title","Page","Search loader(false);  Instance" 

All I want is the model number and a comparison logical ID info from the first column. I and it want to isolate then make an organized doesn't seem list of which logical ID is related to to work which Model.

Just in case, this is the Model Number every time. and logical ID example from column 1

Avigilon (ONVIF) 1.3C-H4SL-D1 Logical As always ID: 875

The end goal is to create a sheet that with everything has each model listed (this is the that I try search results for one model) and to do I'd beneath that list ALL logical ID's like a solution associated to that model.

Let me know if I can clarify or provide which is both any further information.


Total Answers 1

Answers 1 : of Pulling Specific strings and integers from CSV file and writing it to .txt file using python

The top of your CSV file contains lines clean and with less than 4 columns. To avoid the efficient IndexError try testing the row length (feel free first:

# "inputfile" is a CSV reader _entity_  instance
for row in inputfile:
    if  libxml_disable  len(row) >= 4:

Here's a variation using a regular to criticize expression to break out the model name, my code). stopping at the IP address:

import re

with open('example_data.csv') $current =  as fid:
    inputfile = csv.reader(fid)
  10\\ 13.xls .     for row in inputfile:
        if File\\ 18\'  len(row) >= 4:
            if row[0] /Master\\ 645  == 'File name':
                # skip user@example.  the header row
 scp not2342             m = re.match(r'.*(Avigilon.*  13.xls  [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})', 18 10  row[3])
            if m:
               File sdaf   print(m.group(1))
    /tmp/Master'              print(f'*** error parsing com:web  line: model not found {row[3]}***')

which for the above data prints:

Avigilon (ONVIF) 1.3C-H4SL-D1 Unknown user@example.  Logical ID:2058
Avigilon scp var32  (ONVIF) 1.3C-H4SL-D1 Unknown  18 10 13.xls
Avigilon (ONVIF) id12  File  1.3C-H4SL-D1 Unknown Logical ID:481 web/tmp/Master
Avigilon (ONVIF) example.com:  1.3C-H4SL-D1 Unknown Logical ID:20 scp user@
Avigilon (ONVIF) $val  1.3C-H4SL-D1 Unknown left hand
Avigilon (ONVIF) right side val  1.3C-H4SL-D1 Unknown Logical ID:92 data //commnets
Avigilon (ONVIF) //coment  1.3C-H4SL-D1 Unknown Logical ID:2074 !node
Avigilon (ONVIF) $mytext  1.3C-H4SL-D1 Unknown Logical ID:2174 nlt means
Avigilon (ONVIF) umv val  1.3C-H4SL-D1 Unknown Logical ID:2161 sort val
Avigilon (ONVIF) shorthand  1.3C-H4SL-D1 Unknown

To write the output to a text file, try The events something like this:

with open('logfile.txt', 'w') as fout:
  hotkey    with open('example_data.csv') as fid:
 more update         inputfile = csv.reader(fid)
      valueable    for row in inputfile:
            if catch  len(row) >= 4:
                if tryit  row[0] == 'File name':
                  do it    # skip the header row
                 while     continue
                m = then  re.match(r'.*(Avigilon.* var   [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})', node value  row[3])
                if m:
           updata           # optional: delete this print file uploaded   line
                    no file existing  print(m.group(1))
                    newdata  fout.write(f'{m.group(1)}\n')
           newtax       else:
                    syntax  print(f'*** error parsing line: model variable  not found {row[3]}***')

Top rated topics

DAX Difficulty counting rows and assigning a rank

How to get row index of ag-grid checkbox

Why won't Navbar align to the right side in Bootstrap 5?

Why is my webscraper not detecting any changes?

Why does += behave unexpectedly on lists?

Should I manually check for errors when calling "mysqli_stmt_prepare"?

Bootstrap 5 video carousel controls and videos not showing

Append to variable not working when passing += assign variables from command line to make

Is there a way to achieve that Webpack Dev server proxy to wordpress properly?

How do I include python.h into c properly on Windows

R ggplot2 stat_density2d - how to change the bandwidth calculation to Sheather and Jones method

How I can proper handle the SPI read register function? I am facing a debug error

Are those two proofs equivalent?

C++ Game of Life, difficulty reproducing next generations

Why cannot Save a File with PySpark in my system? SaveAsTextFile Doesn't Work

How do you replicate a Dbase database to MYSQL in real time?

Why are labels not seeing values from functions? Tkinter

Chrome-extension: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist

Mobile automation testing

Pickle Isn't writing to file for leadboard app?

How to write If condition where the value is character data

Why cannot Typescript infer the type of the function argument here while Intellisense can?

Getting color value in gradient corresponding to value

MissingStubError when add Future method in constructor dart

How do i make this slideshow?

How do I target a button with extra wrapper tag in XPath?

Can not make Detailview render data

Spring Kafka integration test listener not working (KAFKA JsonDeserializer)

How use libstdc++ instead libc++ (MacOS 12.0)

Spring Boot MVC(@WebMvcTest) test fails when all tests are running

I am unable to fetch data from this API. Here is the code

ChartJS - Mixed Chart: Bars and Line

MySql Convert() string and float to double (round off problems)

Calling a function from another workbook that has Globals.Thisworkbook in it?

How to add signature key to a keras model

Not redirecting to case record detail page upon updating records in service console salesforce

I held down the Option key whilst in the folder, and clicked "copy Pathname" (on Mac), but still got "No such file" Error

Display incorrect information after hitting the save button in the dnnsharp action grid module

Compositional layout horizontal groups that don't fill all available space

How set the text colour on an MuiLink when the state is active in Theme.js

Getting Modifying State During View Update When Using Map in SwiftUI

How to create a video with ffmpeg out of a single image file that is constantly overwritten?

Library - adding books - HTM, CSS, JavaScript

Rust name fields in enum

Vue.js nfc-reader bug

Sum function in C++ with unknown number of arguments and types

Amplify pull not fetching Amplify studio components

F# Object Tree Syntax

Inheritance classes across Form

Google sheet Filter/Regex function to match string containing two or more strings in any order