From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <102653649621645.tru64-unix-managers.marc@archive.invalid> From: Klas.Erlandsson () europolitan ! se Date: Tue, 05 Jun 2001 11:30:54 +0000 To: tru64-unix-managers Subject: SUMMARY: Script help X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=102653649621645 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