Python Forum
Removing the unwanted data from a file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing the unwanted data from a file
#6
(Nov-14-2021, 12:39 AM)jehoshua Wrote: I've done a grep search through all these emails and folders. The output is in a file. The data is like this

Quote:family/Smallville, Robert & Mary/28134: Bioelectro healing - https://t.me/bioelectromagnetic_healing

All I want is the URI, so that I'm left with

Quote:https://t.me/bioelectromagnetic_healing

I haven't looked at all your cases, but why even bother with Python for this? AWK is a great little language for text processing things like this. It breaks lines into fields, which by default are separated by spaces and indexed from 1. Hence

Output:
$ echo "family/Smallville, Robert & Mary/28134: Bioelectro healing - https://t.me/bioelectromagnetic_healing" | awk '{print $8}' https://t.me/bioelectromagnetic_healing
The point I'm really trying to make is that that there may be more appropriate tools for a given task. For text processing tasks like this, it is well worth learning some AWK, regular expressions, sed and you already mentioned grep. Since those tools are made for the job, there's less to write yourself, which means less to test and debug and less to go wrong. The Grymoire has great tutorials on these things.

I'm a programmer at work and I often have to deal with text processing tasks like these - sometimes I'll have lists of items that need investigation or I have to do something to manually reprocess them in our systems and those kinds of tools help me focus on that instead of having to write a lot.
jehoshua likes this post
Reply


Messages In This Thread
RE: Removing the unwanted data from a file - by ndc85430 - Nov-14-2021, 07:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to remove unwanted images and tables from a Word file using Python? rownong 2 978 Feb-04-2025, 08:30 AM
Last Post: Pedroski55
Question Unwanted execution of unittest ThomasFab 9 4,714 Nov-15-2022, 05:33 PM
Last Post: snippsat
  HELP on Unwanted CSV Export Output | Using Selenium to Scrape soothsayerpg 0 1,895 Jun-13-2021, 12:23 PM
Last Post: soothsayerpg
  xml file creation from an XML file template and data from an excel file naji_python 1 2,984 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  How to save CSV file data into the Azure Data Lake Storage Gen2 table? Mangesh121 0 2,742 Jun-26-2020, 11:59 AM
Last Post: Mangesh121
  How to eliminate unwanted spaces Mohan 5 4,546 Jun-04-2020, 08:34 AM
Last Post: buran
  Removing Certain Numbers From File chascp 2 3,074 Feb-07-2020, 04:04 PM
Last Post: chascp
  Unwanted delay between looped synth plays WolfeCreek 1 3,031 Aug-02-2018, 09:24 PM
Last Post: Vysero
  Unwanted variable change in module dannyH 2 3,639 May-08-2018, 05:33 PM
Last Post: dannyH
  Unwanted random generation of scripted Shapes in GASP diemildefreude 3 6,606 Oct-23-2016, 03:11 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020