Denny’s OpenBSD Newbies blog

April 30, 2010

More On Text Processing

Filed under: openbsd — Tags: , , , , , , , — denny @ 6:57 pm

I kept fooling around with a text file the other night, trying to get an
exact character count. The file had 11 lines and I came up with 436
characters, counting them manually. That included whitespace between
the letters and numbers. I ran wc(1) on it to see what it would say:

$ wc -m file
          447

That was a difference of 11 more than what I had counted. How come?
Turns out it counts line feeds as characters, too. Okay, how can I get
rid of them to get the same count as I had gotten counting manually?
I can use sed(1) to do it:

$ sed -e ’s/.$//’ file |wc -m
            436

Actually, I can do the same without the -e switch on it. It got thrown in
the mix and then I realized I didn’t need it. We usually don’t think of a
whitespace as a character, but it is. To see how many characters there
are minus whitespace, I can use tr(1):

$ tr -d ‘[:blank:]‘ < file | wc -c
         373

I know the total number of characters including whitespace and line feeds
is 447. Okay, bc(1) to the rescue:

$ echo “447-373″ | bc
         74

If I use space instead of blank it takes out the line feeds too:

$ tr -d ‘[:space:]‘ < file | wc -c
         362

You add the original 11 line feeds to that and you’re back at 373.

You can also count the characters minus the line feeds and whitespaces
while editing the file in vim like so:

%s/\S/&/gn

So, the adventures in text processing continue. :-) Any input on these
methods and any additional ones always welcome and appreciated.

Cheers!

April 16, 2010

Partitioning Trick Update

I added some information on some of the new stuff in the OpenBSD
disklabel(8) portion of the installation process on my page at:

Partitioning Trick

There’s a link there, too, to a good write-up on preserving your disk layout:

Preserving an existing OpenBSD partition layout during a re-install

Also picked up on a good way today to rename multiple files using perl:

ls -1 | perl -nle’$o=$_; s/OLDPATTERN/NEWPATTERN/; $n=$_; rename($o,$n)if!-e$n’

Pretty nifty. You can rename any part of the file names.

Cheers

April 3, 2010

The Last Four Months

Filed under: openbsd — Tags: , , , , , , — denny @ 9:03 pm

Four months come and gone. Sick a lot. Not much accomplished
during that time other than upgrading WordPress on the blog and
installing snapshots on my laptop extra hard drive and also on my
old Pentium 4 desktop. I did manage, also, to test a patch on Nut
(Network UPS Tools) for Stuart Henderson of OpenBSD. Got it
built okay, just never really got it running right. Going to install a new
snapshot, update everything on the box and see if I can get it running
correctly.
If you add a user to aliases as root and intend to get root’s mail, be
sure not to leave it commented out. :-) Ran into all sorts of problems
with the email on the P4 until I found my omission and fixed it. Tried to
use qtool.pl to clean /var/spool/clientmqueue but no dice.
Also tried sendmail and mailq but in the end I had to fall back on
good old rm to get rid of the trash.
Learned that wget doesn’t like wildcards, so when downloading
multiple files all on one line, I can do something like:

wget http://somewhere.com/{01.jpg,02.jpg,03.jpg}

Also started doing my rsync backups over ssh like so:

rsync -e ’ssh -ax -p xxx’ -agrtv /adir/ user@somebox:/adir

After installing a snapshot on my laptop I started adding packages
and finally got around to java. I don’t like installing it, I think it’s just
another security risk too, but I need it for some things I do so I don’t
really have a choice. When I installed the snapshot I tried out the new
auto-partitioning. I don’t necessarily like the way it turned out, since it
seems like a lot of drive space got wasted in places in isn’t needed,
like in /var and /tmp. /usr was only given 2G, so when I started
building java I ran out of space pretty quickly. Got around that by
adding some directories on a second hard drive and adding some
settings to /etc/mk.conf:

ACCEPT_JRL_LICENSE=Yes
USE_SYSTRACE=Yes
WRKOBJDIR=/data/mktemp/obj
DISTDIR=/data/mktemp/distfiles
PACKAGE_REPOSITORY=/data/mktemp/packages

The first line lets java know you agree to the JRL licensing.
The second line is to detect misbehaving Makefiles, scripts, etc.
The next three lines simply save space on the /usr partition
by using the directories on the second hard drive instead of the
standard ones underneath /usr.

That’s about it. Hope to get some more work done shortly. Waiting
on my new OpenBSD 4.7 cds to arrive soon. Then there will be
a whole lot of work to be done.

Cheers!

Powered by WordPress

Rss Feed Tweeter button Facebook button Technorati button Reddit button Myspace button Linkedin button Webonews button Delicious button Digg button Stumbleupon button Newsvine button Youtube button