[SATLUG] I've newly moved to Ubuntu 11.10 and a few SED & bash questions

John-Eric johnericno at gmail.com
Sat Dec 10 18:33:12 CST 2011


Two years ago when I had to reinstall Windows XP to fix an unstable OS, 
I swore never again. When XP crashed and wouldn't boot this week, I 
installed Ubuntu 11.10 on a 16GB flash drive. So far, I'm pretty happy. 
I will install to my Crucial M4 128GB SSD arrives on Tuesday. I started 
using computers in 1973, using a DEC PDP-10 with a paper tape reader. I 
was a pretty good at the command line and batch files in DOS, which I 
still use for quick & dirty tasks today. After staying up all night and 
lots of Googling & reading, I have a few questions about SED in a bash 
script. Since this file can sometimes get quite large, I would like to 
make a single pass through the file, reading each line only once. I have 
placed each substitution on a separate line for easier reading, but is 
there a way to span -e over several lines? I need to know if I've made 
any obvious noobie mistakes and if there are any improvements I can make.
Thanks for your help,
John-Eric

======== Begin thsed.sh
#!/bin/bash
# This script trims the subject line of Thunderbird folder files to make 
duplicates easier to find.
# It would be ideal if this script only evaluated lines that start with 
"Subject:"
# Syntax= sed -e 's/find1/sub1/' -e 's/find2/sub2/g' <old >new
# Syntax= sed '/baz/s/foo/bar/g' #Replace "foo" with "bar" only on lines 
that begin with "Subject:"
#
# input1= Subject: [Group One] (OT) "This is the text." [Archivo Adjunto 1]
# input2= Subject:    {Message: 1234) @##-Some Different Text##@ 
[Archivos Adjuntos 78]
#
sed -e '/^subject:/s/^subject: *[\[\{\(](.*?)[\)\}\]] */Subject: /g'    
#Remove anything inside any mixed pair of [,{,( and ),},] if it follows 
"Subject:"
       -e '/^subject:/s/ fsrv//g'    #Remove "fsrv" anywhere on the line
       -e '/^subject:/s/ \[fsc\]//g'    #Remove "[fsc]" anywhere on the line
       -e '/^subject:/s/ *\[Archivos? adjuntos? *\d+\] */g'    #Remove 
"[Archivo Adjunto 1]" and "[Archivos Adjuntos 78]" and surrounding 
whitespace anywhere on the line
       -e '/^subject:/s/\(\s-\|[^A-Za-z0-9-]\)/ /g'    #Allow only 
alphanumeric characters and spaces
       -e '/^subject:/s/  +/ /g'    #Compress white space
<'/media/RAID-S/Thunderbird/Mail/Local Folders/InFile' 
 >'/media/RAID-S/Thunderbird/Mail/Local Folders/OutFile'

===== End thsed.sh



More information about the SATLUG mailing list