
Top Gun Coolmadness Whoopi Goldberg As Guinan's Eyebrows
- Daniel Beardsmore
- Location: Hertfordshire, England
- Main keyboard: Filco Majestouch 1 (home)/Poker II backlit (work)
- Main mouse: MS IMO 1.1
- Favorite switch: Probably not whatever I wrote here
- DT Pro Member: -
- Contact:
Reading this blog makes me feel like a lab rat who's figured out what's going on and escaped.
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
Discuss!
Speaking of, I was just thinking about the Rats of Nimh. Good story. I liked the books as a kid. I wonder if the writing will rate now. I wasn't too stoked when I re-read some Redwall books so I decided to keep them as good memories rather than re-read the entire series of what is practically the same story. I have a Redwall tattoo though and I'm probably gonna get another one.

- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
Hm, I've got a scripting question and I know there are some pretty sharp folks that deign to visit my Blog (I can't imagine why but hello chaps) so I won't burden our Fledgling (m'webwit) Club with an unnecessary thread. Unless this doesn't work out. Then I'm headin' out to Off-Topic,
I have this for loop I'm working on and it strikes me that the way I'm doing it is sort of clunky. At least, I know there are at least five ways I could do this more elegantly but I'm just not really sure what they are. Here's the do part:
frankly, copying to a temp file and then moving it back four times feels pretty disgusting. revolting? i'm perturbed.
my first idea is to figure out a way to run the sed all at once on a temp file and then move it back once all the work is done. that would save like four redundant cps but I'm not sure how to do that. nested loop? is that possible? god help me. or 7bot.
I have this for loop I'm working on and it strikes me that the way I'm doing it is sort of clunky. At least, I know there are at least five ways I could do this more elegantly but I'm just not really sure what they are. Here's the do part:
Code: Select all
do
# make a working file from the target file
cp "$f" "$f"_tmp
# find and replace a variable
sed 's/\_\@fg_color/$fgcolor/g' > "$f"_tmp
# rename the working file to the target file
mv $f_tmp $f
sed 's/\_\@bg_color/$bgcolor/g' "$f"_tmp
mv $f_tmp $f
sed 's/\_\@link_color/$linkcolor/g' "$f"_tmp
mv $f_tmp $f
sed 's/\_\@disabled_color/$disabledcolor/g' "$f"_tmp
mv $f_tmp $f
done
my first idea is to figure out a way to run the sed all at once on a temp file and then move it back once all the work is done. that would save like four redundant cps but I'm not sure how to do that. nested loop? is that possible? god help me. or 7bot.
- Halvar
- Location: Baden, DE
- Main keyboard: IBM Model M SSK / Filco MT 2
- Favorite switch: Beam & buckling spring, Monterey, MX Brown
- DT Pro Member: 0051
sed is nifty, I wish I could do more in it.
I'm not wholly getting what files you are trying to manipulate (does the script work in its current form?)
Anyway, whatever else you're doing there, you can put more than one command in one call of sed using {} :
I'm not wholly getting what files you are trying to manipulate (does the script work in its current form?)
Anyway, whatever else you're doing there, you can put more than one command in one call of sed using {} :
Code: Select all
sed '{
s/\_\@fg_color/$fgcolor/g
s/\_\@bg_color/$bgcolor/g
s/\_\@link_color/$linkcolor/g
s/\_\@disabled_color/$disabledcolor/g
}' "$f"_tmp
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
you sly dog. i had no idea you could do that with sed; that may be just what the doctor ordered. I'm still working on the script leading up to this point so I can't test it quite yet but I think that's on the right track. thanks manHalvar wrote: sed is nifty, I wish I could do more in it.
I'm not wholly getting what files you are trying to manipulate (does the script work in its current form?)
Anyway, whatever else you're doing there, you can put more than one command in one call of sed using {} :
Code: Select all
sed '{ s/\_\@fg_color/$fgcolor/g s/\_\@bg_color/$bgcolor/g s/\_\@link_color/$linkcolor/g s/\_\@disabled_color/$disabledcolor/g }' "$f"_tmp

basically this script is trawling through a set of predefined files and replacing a temporary placeholder with the contents of a variable that is set earlier in this script.
- 7bit
- Location: Berlin, DE
- Main keyboard: Tipro / IBM 3270 emulator
- Main mouse: Logitech granite for SGI
- Favorite switch: MX Lock
- DT Pro Member: 0001
@sth: Your script does not what you want it to do.
The most primitive way would have been to do it as a pipe, but Halvar's version is more elegant.
However, you can do it even shorter: 
The most primitive way would have been to do it as a pipe, but Halvar's version is more elegant.
However, you can do it even shorter:
Code: Select all
's/\_\@\(fg\|bg\|link\|disabled\)_color/$\1color/g'

- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
here's what I have so far,
Code: Select all
for f in "$THEMES"
do
sed 's/\_\@fg_color/$fgcolor/g;s/\_\@bg_color/$bgcolor/g;s/\_\@link_color/$linkcolor/g;s/\_\@disabled_color/$disabledcolor/g' > "$f"_tmp
mv "$f"_tmp "$f"
done
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
now that's the kind of corn i'm trying to shuck here. after i get the basic functionality hammered out, the obfuscation beginsCode: Select all
's/\_\@\(fg\|bg\|link\|disabled\)_color/$\1color/g'
![]()

- 7bit
- Location: Berlin, DE
- Main keyboard: Tipro / IBM 3270 emulator
- Main mouse: Logitech granite for SGI
- Favorite switch: MX Lock
- DT Pro Member: 0001
I'm not 100% sure what you want to do, but it should be better this way:
Code: Select all
for f in "$THEMES"
do
sed -i 's/\_\@\(fg\|bg\|link\|disabled\)_color/$\1color/g' $f
done
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
i've been doing this
because i didn't know you could actually edit the file with sed. I thought the point was to edit a text stream, but it would normally leave the input file intact and leave you to do something else with the stream when it's done.
i guess i can let on what i'm doing. basically this is a script that requests some hex values and then edits a bunch of config files to change some variables into those hex values. what i was doing was making the copy during/after the replacement, and then once the replacement is done, moving the copy back to its original name. that's the complete for loop up there; the rest of the script is probably not important to this particular portion.
Code: Select all
for f in "$THEMES"
do
sed 's/\_\@\(fg\|bg\|link\|disabled\)_color/$\1color/g' > "$f"_tmp
mv "$f"_tmp "$f"
done
i guess i can let on what i'm doing. basically this is a script that requests some hex values and then edits a bunch of config files to change some variables into those hex values. what i was doing was making the copy during/after the replacement, and then once the replacement is done, moving the copy back to its original name. that's the complete for loop up there; the rest of the script is probably not important to this particular portion.
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
holy clam cakes*. sed -i. look, i CAN read. and learn.
but for portability's sake, i still wonder if I should do it the olden way. gnu... we live with it, and it works fine enough for me, but some people feel more strongly about their environment.
edit= can't settle on an exclamation.
but for portability's sake, i still wonder if I should do it the olden way. gnu... we live with it, and it works fine enough for me, but some people feel more strongly about their environment.
edit= can't settle on an exclamation.
- Muirium
- µ
- Location: Edinburgh, Scotland
- Main keyboard: HHKB Type-S with Bluetooth by Hasu
- Main mouse: Apple Magic Mouse
- Favorite switch: Gotta Try 'Em All
- DT Pro Member: µ
Forum feature request: option to render code blocks as Emoji. Cause none o what you gentlemen been saying gone done make a single lick of sense to yours true. Might as well have been cat pictures to me. Good IDEs accept those nowadays, surely?
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
given a capable parser there are a lot of ways you could substitute commands/operations for emojis

but i'm not even coding. this is just bash scripting. child's play. for children. i am a child.







- Halvar
- Location: Baden, DE
- Main keyboard: IBM Model M SSK / Filco MT 2
- Favorite switch: Beam & buckling spring, Monterey, MX Brown
- DT Pro Member: 0051
Regular expressions are designed to be indistiguishable from magic for the uninitiated.
https://xkcd.com/208/
https://xkcd.com/208/
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
one of my favorite parts of xkcd is having seen randall's attitude go from humorous insecurity to, like, pretty much the total opposite: http://xkcd.com/1053/Halvar wrote: Regular expressions are designed to be indistiguishable from magic for the uninitiated.
https://xkcd.com/208/
that strip really brightened my outlook!
- Muirium
- µ
- Location: Edinburgh, Scotland
- Main keyboard: HHKB Type-S with Bluetooth by Hasu
- Main mouse: Apple Magic Mouse
- Favorite switch: Gotta Try 'Em All
- DT Pro Member: µ
Sed, huh? I used awk once. To process star catalogues into xyz coordinates, which was pretty nice. I then rewrote my script to generate lists of the brightest stars visible from any given 3D point inside that model of our corner of the galaxy. And then five minutes went by and I forgot everything I learned about awk.
Programmer's mind: I don't have it!
Programmer's mind: I don't have it!
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
the regex don' work. it don't properly 'spand the variable with $\1color. already done changed to single quotes. jus' don' like it i guess. what'n ends up hap'nin's that the sed machine replaces the text with the name of the dang variable, not it's ol' contents.
so'ns i get this type'a nonseense:
window.inactive.border.color: $bgcolor
menu.border.color: $bgcolor
window.active.client.color: $fgcolor
window.inactive.client.color: $bgcolor
i reckon the problem is the regex leadn' up to it. sed, you're a literal somebitch and a harsh mistriss.
so'ns i get this type'a nonseense:
window.inactive.border.color: $bgcolor
menu.border.color: $bgcolor
window.active.client.color: $fgcolor
window.inactive.client.color: $bgcolor
i reckon the problem is the regex leadn' up to it. sed, you're a literal somebitch and a harsh mistriss.
- Muirium
- µ
- Location: Edinburgh, Scotland
- Main keyboard: HHKB Type-S with Bluetooth by Hasu
- Main mouse: Apple Magic Mouse
- Favorite switch: Gotta Try 'Em All
- DT Pro Member: µ
Ole Sed's just foolin' with ya, Sth. Gone get him some Dutch hospitality an he might well limber up to ya, all's I'm sayin'. 'N if it don't gone work by day's end, threaten him with a Bourne Again Shell between the eyebrows! Concentrates the mind, they say.
- sth
- 2 girls 1 cuprubber
- Location: US
- Main keyboard: hhkb1
- DT Pro Member: -
hell! i've been approaching this the wrong way. 7bit, your way is pretty but i don't think regex will save me there because i need the variables to expand at the same time sed is writing the substitution, and it doesn't, which makes sense because it's not his job to do that. i think i may have to settle for a slightly more redundant way of doing this until i can think of something novel.
- scottc
- ☃
- Location: Remote locations in Europe
- Main keyboard: GH60-HASRO 62g Nixies, HHKB Pro1 HS, Novatouch
- Main mouse: Steelseries Rival 300
- Favorite switch: Nixdorf 'Soft Touch' MX Black
- DT Pro Member: -
Why not just use lxappearance? It's small, lightweight, very few dependencies, and easier than writing your own gtkrc.