tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: Script help
@ 2001-06-05 11:30 Klas.Erlandsson
  0 siblings, 0 replies; only message in thread
From: Klas.Erlandsson @ 2001-06-05 11:30 UTC (permalink / raw)
  To: tru64-unix-managers

Hi!

My question was:
"I have a big text file I want to edit.
Everywhere there is 11|XXXXX
I want to remove the last X (X could be any character) .
How do I solve this?"

I got many answers and many of them where the same and some had
misunderstood but 
here I have the solution and with a well written explanation written by Mark
Deiss.
Thanks everybody!!!!

****************************************************************************
*****
"Usually would suggest ed command and perform an inline edit, but for this
you
may want to use sed and do a comparision of your final editted results
beforing
moving the editted version back over the top of the original.

$sed -e 's/\(11|....\)./\1/g' original_file > editted_file

Explanation of the regexp - the pattern \(11|....\) is holding any pattern
beginning with "11|" followed by any four characters into the first buffer.
So
the follow on "." is matching against the last character (5th X) that you
intend
to delete. Then in the second pattern space, only the content in the first
buffer is being brought back in; effectively you have now deleted the 5th
character . The initial "s" is signifying that you are performing a
substitution
operation and the trailing "g" signifys that you want to do this for every
occurrence found on any line. If you do not use the "g", then only the first
occurrence of your pattern on any line will be modified.

$diff original_file editted_file | more

Check that your edits are what you expected.

$mv editted_file original_file

If you want to replace your original with the editted version.

Regards Klas

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-06-05 11:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-06-05 11:30 SUMMARY: Script help Klas.Erlandsson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox