Sponsored Content
Operating Systems OS X (Apple) Need Help with GREP REGEX scripts for common BB-EDIT text-editing Post 302608331 by TheMacGuy on Saturday 17th of March 2012 03:44:28 AM
Old 03-17-2012
Need Help with GREP REGEX scripts for common BB-EDIT text-editing

Hi Everybody..

I'm a "newbie" to using Command-line... A few half-remembered DOS commands from 30 years ago, and the very handy "Sudo rm -R pathname" REMOVE command...

I do a lot of "cleaning" of plain-text OCR text files. with assorted common
line-break, punctuation and capitalization errors..

IF there's a "recipe book" of simple GREP commands that are "obvious how to use" (for a newbie... :-) I'd love to see it!!! (haven't found it YET!)

Meanwhile, here's the part that's giving me a migraine.. Help, Please!

-----------

I'm having trouble figuring out how to "clean" a text-file of extraneous formatting problems using GREP commands in my "BB-EDIT" (Macintosh) text-program;

I'm trying to clean out a pair of carriage-returns in between a "broken" paragraph (lowercase letter ending para.1, and lowercase letter starting para.2 with NO PUNCTUATION in between, just two line-break \r characters...

My ATTEMPT isn't quite working.
I'm trying to use the GREP command [a-z]\r{2}

to replace the two line-breaks between paragraph1 and paragraph2, (that is, the anchorpoint is the LAST l/c character of the FIRST part of the broken-paragraph)
-----without affecting the end or start letters of the two paragraphs....


THIS GREP STRING **IS** finding the EXACTLY TWO carriage returns PRECEEDED BY a l.c. letter [a-z]

But it is *NOT* "remembering" that PRECEEDING lower-case letter....

So, "Mary had a little lamb

who had snowy green fleece....

is being replaced with "Mary had a little lam who had snowy green fleece.....

Does anybody have such a GREP pattern (and a simple explanation of it, if possible!) that will find [a-z]\r\r[a-z] and REPLACE the two carriage returns with a single-space----WITHOUT affecting the two lowercase letters at the end of paragraph1 and beginning of paragraph2

Any Ideas how I can fix this??? Please advise!! Thank-you!!


TRY THIS TOO:

Pattern Matches
(p) the pattern p and remembers it
(?P<NAME>p) the pattern p and remembers it by the specified string NAME


So, if I'm reading this correctly, modelling from my "broken" expression above it should be:
Find: ([a-z]\r{2})
Replace [a-z\r{2}]

---Nope, that doesn't work (for me) either.... Somethings' wrong here, but what???
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Text Editing

Hello everybody, I have a sorted text file. some of the lines appear twice or even more. is there an unix utility that removes the extra appearences? Thanks, Ido. (7 Replies)
Discussion started by: ginodii
7 Replies

2. UNIX for Dummies Questions & Answers

editing sqlplus id@passwd in multiple scripts, users and directories

hi all, i was given by my supervisor a task to search for scripts which contain oracle sqlplus i.e "myusername/mypasswd @myDB" in every /home/userfolder, which are, all the scripts made by different user. I've done some find command to search string for sqlplus, but it may up too long to respond.... (8 Replies)
Discussion started by: Helmi
8 Replies

3. Shell Programming and Scripting

script to search and edit scripts

Hi all, can you please help me in this one.. i have a many scripts in a directory & i get many requests to change the code of a particular script. for example file abc.txt contains #!/bin/bash mumbai 102403445 chennai 123980123 delhi 3456268468 kolkata 465376832 #kolkat 462945959 ... (3 Replies)
Discussion started by: geeko
3 Replies

4. Shell Programming and Scripting

Text editing script does everything but edit text.

I wrote this script to create and edit a large number of websites based on a template site and a collection of text files which have the relevant strings in them delimited by colons. I run it and the shell doesn't produce any errors, but when it gets to the for loop where it actually has to edit... (2 Replies)
Discussion started by: afroCluster
2 Replies

5. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

6. Debian

Problems with Crontab not executing scripts after edit

Hi all I installed Debian and i have a few scripts that outputs what is happening. The wierd part...after fresh install all works ok but after i open or edit Crontab it stops executing the scripts...and scripts runs manually so its not a problem with scripts...what happens is that i usually... (3 Replies)
Discussion started by: ro0t3d
3 Replies

7. Shell Programming and Scripting

Edit Text

Hi everyone , i am new in shell scripting and i want to do a simple job. A have in a file a text that looks like : 4770 maniac 20 0 13680 312 240 S 0.0 0.0 0:00.00 pro 4770 maniac 20 0 23448 312 240 S 0.0 0.0 0:00.00 pro 4770 maniac 20 0 33216 312 240 S 0.0 0.0 0:00.00 pro and i want to... (2 Replies)
Discussion started by: pcmaniac
2 Replies

8. Shell Programming and Scripting

Find common terms in two text file, xargs, grep

Hello, I'm interested in finding all occurrences of the terms in file1 in file2, which are both csv files. I can do this with a loop but I'm interested in knowing if I can also do it with the help of xargs and grep. What I have tried: cat file1 | xargs grep file2 The problem is that... (15 Replies)
Discussion started by: eon
15 Replies

9. Shell Programming and Scripting

Convert vi editing to text editing

Dear Guru's I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response. Srini (6 Replies)
Discussion started by: thummi9090
6 Replies

10. Shell Programming and Scripting

Need grep regex to extract multiline text between two strings

I have a file conatining the below: --- 10.9.16.116: /tmp/5835113081224811756.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb /tmp/4603745991442278706.jar: hash: e6df90d38fa86f0e289f73d79cd2cfd2a29954eb 10.9.14.126: /tmp/conf/extra/httpd-ssl.conf: hash:... (1 Reply)
Discussion started by: mohtashims
1 Replies
BZGREP(1)						      General Commands Manual							 BZGREP(1)

NAME
bzgrep, bzfgrep, bzegrep - search possibly bzip2 compressed files for a regular expression SYNOPSIS
bzgrep [ grep_options ] [ -e ] pattern filename... bzegrep [ egrep_options ] [ -e ] pattern filename... bzfgrep [ fgrep_options ] [ -e ] pattern filename... DESCRIPTION
Bzgrep is used to invoke the grep on bzip2-compressed files. All options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If bzgrep is invoked as bzegrep or bzfgrep then egrep or fgrep is used instead of grep. If the GREP environment variable is set, bzgrep uses it as the grep program to be invoked. For example: for sh: GREP=fgrep bzgrep string files for csh: (setenv GREP fgrep; bzgrep string files) AUTHOR
Charles Levert (charles@comm.polymtl.ca). Adapted to bzip2 by Philippe Troin <phil@fifi.org> for Debian GNU/Linux. SEE ALSO
grep(1), egrep(1), fgrep(1), bzdiff(1), bzmore(1), bzless(1), bzip2(1) BZGREP(1)
All times are GMT -4. The time now is 05:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy