Need Help with GREP REGEX scripts for common BB-EDIT text-editing


 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Need Help with GREP REGEX scripts for common BB-EDIT text-editing
# 1  
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???
# 2  
Old 03-21-2012
I don't think that the grep command is going to help because grep never changes the file.
You will need a sed command to read your input file, edit the data and produce a new corrected output file.

Best suggestion is to re-post in Shell Scripting after condensing your post to the basics.
The normal line terminator for text files in MACOS depends on the Operating System version. Please post the exact version of your O/S and state what is the normal line terminator in a text file for your version of MACOS. Please post an example input file and the expected output and explain the process concisely.

The output from this (coincidentally) sed command on a representative sample portion of the input file should clear up any ambiguities about the text file format and make the extraneous characters visible.
Code:
sed -n l filename


Last edited by methyl; 03-21-2012 at 10:54 AM.. Reason: try to be unambiguous
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question