I started playing around with Python (2.6.6) trying to parse a file. No matter what I tried so far I am not able to print only the lines/group/backreference that have been affected by the substitution. Instead I get also the other lines too
File to parse:
Current code:
I assume there is something needed like the behavior of sed's -n and /p to basically print nothing but the lines that have been matched.
Output:
Expected output:
I saw that there are more functions/methods in the module re like re.group etc. but I would like to know why it doesn't work with my example.
Thanks in forward for a hint with this rather basic problem.
Thank you, itkamaraj. I had it tried so far with match() and search() and it didn't work.
Now I just noticed why - I used:
...where I assumed I can use just a part of a pattern like when you use Linux/Unix grep; this seems not working so I have to use at least something like:
cheers
zaxxon
Last edited by zaxxon; 09-01-2016 at 09:24 AM..
Reason: clarification, typos
Hi all...
As you know I like making code backwards compatible for as many platforms as possible.
This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Hi,
Please can you tell me what the last two lines in the python code below are doing?
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
print 'data has %d characters, %d unique.' % (data_size,... (2 Replies)
Hello everyone,
Here's the problem, I have a list generated by this command;
watch -n 5 'iptables -nvL | grep "DROP"'
It generates output that looks like this (severely truncated for clarity)
Every 5.0s: iptables -nvL | grep "DROP" ... (2 Replies)
Is there any way to produce a code with all use dmacro to be substituted up to 'ready for compilation' condition?
Some macro are build up and it is hard to replace all them up to final code by hand.
I need to see the final line after all macro been applied by preprocessor.
How that could be... (5 Replies)
I try to run this script, however, it gives an exception in line 3. How do I do an assignment to a substituted variable?
#!/bin/bash
name=fruit
ext_$(eval echo ${name})=apple
tmp=ext_$(eval echo ${name})
if ]; then
echo "apple"
elif ]; then
echo "orange"
fi
echo ${!tmp}
Error... (2 Replies)
I have to stop the output of dd from writing to terminal. Here is the command:
sudo dd if=boot1h of="/dev/r$temp1"
Here is the output:
2+0 records in
2+0 records out
1024 bytes transferred in 0.000804 secs (1273715 bytes/sec)
I have tried >> log.txt but it doesn't work. Is there... (4 Replies)
In a file, field separetor in line is irregular number of spaces, so I canot use field in sub function to get my charecter replaced with empty space. I would like to substitute only one perticular charecter with space at perticular posiotn, so I canot use perticular character as that may occur... (6 Replies)