:set list
# see control chars (tabstops, control characters, etc)
Friday, May 29, 2009
Example of processing multiline records with awk
Processing multiline records is tricky. It is easier to use blank lines as record separators.
#example records
ink1 4.99
red
ink2 5.99
yellow
awk ' BEGIN { RS=""; FS=" "} { r1=$1; r2=$2; r3=$3; print "***Record***" r1 " " r2 " " r3 }' inks
#What it prints out
***Record***ink1 4.99
red
***Record***ink2 5.99
yellow
#example records
ink1 4.99
red
ink2 5.99
yellow
awk ' BEGIN { RS=""; FS=" "} { r1=$1; r2=$2; r3=$3; print "***Record***" r1 " " r2 " " r3 }' inks
#What it prints out
***Record***ink1 4.99
red
***Record***ink2 5.99
yellow
Thursday, May 28, 2009
Creating a mysql user and granting privileges
//standard way of creating a user
CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
//Creating a user and granting privileges:
GRANT ALL PRIVILEGES ON table.* TO 'user'@'localhost' identified by 'password'
//Show privileges for a user:
show grants for 'user'@'localhost'
CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
//Creating a user and granting privileges:
GRANT ALL PRIVILEGES ON table.* TO 'user'@'localhost' identified by 'password'
//Show privileges for a user:
show grants for 'user'@'localhost'
Install Windows nic driver on Linux
#Download ndiswrapper
make #this will install the kernel module (after compiling)
modprobe ndiswrapper
ndiswrapper -i driver.inf
ndiswrapper -m #generate modprobe alias for ndiswrapper
#restart
#Check installed drivers:
ndiswrapper -l
make #this will install the kernel module (after compiling)
modprobe ndiswrapper
ndiswrapper -i driver.inf
ndiswrapper -m #generate modprobe alias for ndiswrapper
#restart
#Check installed drivers:
ndiswrapper -l
Showing a decimal expansion with bc
#3 digits after the decimal place
echo "scale=3; 41.0 / 939.0" | bc
echo "scale=3; 41.0 / 939.0" | bc
Wednesday, May 27, 2009
awk script to generate count of each program
#csv of format:
#the_program, any_data, any_data, ....
#
#this script counts number of repetitions of a program
cat program-list.csv | awk -F',' '/[a-zA-Z0-9]+/{print $1}' | sort | uniq -c
#the_program, any_data, any_data, ....
#
#this script counts number of repetitions of a program
cat program-list.csv | awk -F',' '/[a-zA-Z0-9]+/{print $1}' | sort | uniq -c
Tuesday, May 26, 2009
Subscribe to:
Posts (Atom)