Geany - automate "replace" with regular expressions??

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#31 Post by MochiMoppel »

technosaurus wrote:sed only does 1 line at a time so \n will never match...
...but it can combine 2 lines, using the N command, and then it can match \n, or better - if the character before TEXT is unknown - it can match whatever character precedes TEXT.

@greengeek: You should attach an example of your raw messages, otherwise we don't know what kind of characters you are dealing with.

You should also clarify if you are still searching for a way to do it with Geany's Find & Replace or without Geany. Ironically Geany's regex patterns can be more powerful than what you can use with sed, but since you can't chain these commands as you would with sed, Geany is limited to one command - not enough for complex tasks.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#32 Post by musher0 »

Hi, greengeek.

You're right, replaceit could do only part of the job. So here's my take on it,
double-spaced! :)

Code: Select all

#!/bin/ash
# greengeek_msgs2.sh
# musher0, July 2nd 2015.
####
cd ~/my-documents
GRGK="essai-greengeek.txt";NH="/tmp/no-header"
MRM="/tmp/more_readable_msgs.txt"
FST="/tmp/1st-field";SND="/tmp/2nd-field"
#
cat "$GRGK" | awk -F":" '{ print $2 }' > $NH
awk '$1 !~ /02/ { print "\n\t" $0 }' $NH > $SND
awk '$1 ~ /02/ { print "\n" $0 }' $NH > $FST
paste $FST $SND > $MRM
clear;cat "$MRM";echo # You can comment out this line.
Illustrated below. BFN.

musher0
Attachments
capture31318.jpg
(12.46 KiB) Downloaded 183 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#33 Post by greengeek »

musher0 wrote:So here's my take on it,
double-spaced! :)
salut musher0
double interligne est bon. Je peux interleave le "sentbox" messages dans l'espace
Veuillez excuser la grammaire de la babelfish s'il vous plait!
merci bien.

EDIT :Il y a aussi un autre défi:
Le fichier texte complet contient plus de données à ignorer

Je m'excuse!
Attachments
context.jpg
(27.33 KiB) Downloaded 153 times
double-espace.jpg
(9.19 KiB) Downloaded 145 times

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#34 Post by greengeek »

MochiMoppel wrote:You should attach an example of your raw messages, otherwise we don't know what kind of characters you are dealing with.

You should also clarify if you are still searching for a way to do it with Geany's Find & Replace or without Geany. Ironically Geany's regex patterns can be more powerful than what you can use with sed, but since you can't chain these commands as you would with sed, Geany is limited to one command - not enough for complex tasks.
Well, I started with manual extraction of the data from each raw sms text file, then I realised the search/replace functions of Geany could make the job so much easier - then I read about regex functions and thought that might help me with getting the most out of Geany - then as a result of the various comments on this thread i realised that I don't have to process one file at a time - I can handle a whole directory of sms files, but it is unlikely that using Geany will be the best way to handle an entire directory of raw sms backups (although it does appear to have the ability to handle an entire "session" rather than just a single document).

So I am at the point where i would like to continue this thread for the purposes of learning more about the power of regex functions within Geany (I'm sure i will need better understanding of this), but I think I should also start a new thread to look at various methods of handling the specific sms backup files that have been the original source of the textfiles I started with in this thread.

The new thread evaluating methods of extracting the required data from the backed up sms files is here

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#35 Post by 6502coder »

I have a new version of the dt.awk script. See my post in your new thread.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#36 Post by greengeek »

Here is an important note from technosaurus:
technosaurus wrote:Just thought I would mention that as of 1.25 geany (released this month) has a checkbox to allow multiline regex or otherwise uses sed-style matching.
Quoted from other thread here

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#37 Post by MochiMoppel »

Today I could take a first look at this new "multiline regex" thing. I'm not impressed. Unless I did something wrong the way to perform multiline searches can get terribly complicated. While in normal regex patterns something like foo.*bar will match foo and bar and any characters between them, provided that foo and bar are on the same line, the multiline option doesn't remove this limitation. The '.' wildcard wouldn't include linefeeds.

Post Reply