Linux, programming, computers and life

July 31, 2008

memset64, anyone?

Filed under: programming, c++

I wonder why memset is the only mean we have in libc in order to fill memory. We are limited to filling the memory with certain char. What if i want to use longer pattern? Is there anything like memset64? Generally, i’d like to fill the buffer with pattern which is 4 or 8 bytes long. I’m pretty sure, that’s the way memset is implemented anyway, for performance.
Maybe i’m missing something, but i was unable to find anything like this in the libc.

July 22, 2008

searching your organization address book from command line

Filed under: CLI, programming

Let’s assume that you are working in a relatively small organization, 4-5 hundreds people at most. I’m sure you have some kind of intranet and there’s a phone book there. I’m pretty sure you have a page with most used phone numbers pinned on your wall somewhere.
Here’s idea how to search those phones from command line. The solution is based on two scripts. First downloads the names list and formats it as necessary (mine strips all HTML mumbo-jumbo). This one is called periodically by cron. Second is used for names list search.

Here are the scripts:
update_tel_db
#! /bin/sh

cd /your/path/to/database
wget http://your.path.here/file.here >& /dev/null
touch tel.txt ; \rm tel.txt
links -dump file.here | grep @ | grep -v — ——————– | grep -v mailto | grep -vi ‘Click here’ | grep -v javascript | grep -v IMG | grep -v file: | tr ‘|’ ‘ ‘ | sed ’s/^ *//’ | sed ’s/ / /g’ | sed ’s/\[[0-9]*\]//g’ > tel.txt
\rm file.here >& /dev/null
touch tel.txt

tel
#! /bin/bash

echo ‘NAME DPT OFFICE CELL-PHONE HOME E-mail’
grep -i $1 /tour/path/here/tel.txt

Now telephone search becomes tel name on the command line.
Enjoy :)

July 20, 2008

adding command output to each line of file

Filed under: CLI, programming, awk

I wrote about changing of certain columns in a file, but here let’s solve a simpler task. I’d like to add something, let’s say date, to every line of a file. I’ll emulate a file using `seq 1 10`.

The following is easy enough:
seq 1 10 | awk '{print "echo `date` "$0}' | bash

However, there’s simpler solution:
seq 1 10 | while read ; do echo `date` ${REPLY} ; done

It works because REPLY variable is set to the line of input read by the read builtin command when no arguments are supplied (from bash manpage).

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers