http://www.1stwebdesigner.com/css/customize-twitter-search-widgets/
Twitter widget customization, after copying the code from a currently embedded widget like the one on here ;)
Thursday, 20 September 2012
Tuesday, 18 September 2012
Awk, Sed and TR
I used Awk, but had issues with removing whitespace and inserting commas.
I had a poorly written Awk text file script, that filled out 19 fields with info. Done in thee style of a none-programmer.
{ FS = "," } ; # comma-delimited fields
{ sub($1,"")}
{firstname=$3}
{surname = $4}
{group = $8}
{username =tolower( $3"."$4)}
.....
#more fields here zzzzzzzzz
.....
{$16=" "}
{$17=" "}
{$18=" "}
{$19=" "}
{print}
which was invoked like this:
awk -f mybadscript.awk mydata.csv > newdata.csv
Then I had to run Sed
sed 's/[:space:]+/,/g' newdata.csv > afterseddata.csv
http://stackoverflow.com/questions/8766165/using-awk-to-remove-whitespace
Then ran TR
tr ' ' ',' < afterseddata.csv > aftertrdata.csv
http://stackoverflow.com/questions/1271222/replace-white-spaces-with-a-comma-in-a-txt-file-in-linux
Phew. Perl might be easier next time.
I had a poorly written Awk text file script, that filled out 19 fields with info. Done in thee style of a none-programmer.
{ FS = "," } ; # comma-delimited fields
{ sub($1,"")}
{firstname=$3}
{surname = $4}
{group = $8}
{username =tolower( $3"."$4)}
.....
#more fields here zzzzzzzzz
.....
{$16=" "}
{$17=" "}
{$18=" "}
{$19=" "}
{print}
which was invoked like this:
awk -f mybadscript.awk mydata.csv > newdata.csv
Then I had to run Sed
sed 's/[:space:]+/,/g' newdata.csv > afterseddata.csv
http://stackoverflow.com/questions/8766165/using-awk-to-remove-whitespace
Then ran TR
tr ' ' ',' < afterseddata.csv > aftertrdata.csv
http://stackoverflow.com/questions/1271222/replace-white-spaces-with-a-comma-in-a-txt-file-in-linux
Phew. Perl might be easier next time.
Monday, 17 September 2012
Awk substitute and concatenate columns
Using Awk
awk -F, '{ sub($1,"");temp = $3"."$4; $2 = temp; print}' myfile.csv
set delimiter as comma, then removes column 1 sub from "", takes column 3 and 4 and concatenates with a full stop in between them, and puts that in column 2
This was used so i could take a name in a file with a first and last name and create a username like joe.bloggs
Another useful Awk feature is sub strings
awk -F, '{ sub($1,"");temp = $3"."$4; $2 = temp; first= substr($3,1,1); second = substr($4,1,1); $5=first second ; print}' myfile.csv
substr($3,1,1) takes first char of column 3 puts it in variable first
substr($4,1,1) takes first char of column 4 puts it in variable second
$5 = first second prints these 2 chars together, no spaces
Use on Joe Bloggs to create new column with contents - JB
This used the substr function
Every good boy.
awk '{print substr($1,1,1)}' temp returns E
awk '{print substr($1,3)}' temp returns ery
awk '{print substr($2,3)}' temp returns od
awk '{print substr($0,7,2)}' temp returns go
Thanks to http://unix-simple.blogspot.co.uk/2006/10/awk-substr-function.html for examples
Subscribe to:
Posts (Atom)