sed – Add 0 values to records in an existing file

May 7, 2013 Leave a comment

Just noting this here for future reference.

Problem:
The full problem is stated here. This is just a simplified version.

Input:

N/A124 14 0.8 1051670971100000
N/A125 15 0.8 1051670971100001
N/A126 16 0.8 1051670971100002
N/A127 17 0.8 1051670971100003

Output:

N/A124000014 0.8 1051670971100000
N/A125000015 0.8 1051670971100001
N/A126000016 0.8 1051670971100002
N/A127000017 0.8 1051670971100003

Solution:
There were other solutions but this one with sed caught my attention.

$ echo "N/A124    14 0.8    1051670971100000
N/A125    15 0.8    1051670971100001
N/A126    16 0.8    1051670971100002
N/A127    17 0.8    1051670971100003" | \
sed ":a; s/^\(.\{6,11\}\) /\10/; ta;"
N/A124000014 0.8    1051670971100000
N/A125000015 0.8    1051670971100001
N/A126000016 0.8    1051670971100002
N/A127000017 0.8    1051670971100003

This is what I think sed is doing. (Please correct me if I’m wrong)
:a – Create a label
s/^\(.\{6,11\}\) /\10/ – Group the first 6 to 11 characters, Substitute the match (ie first 6 to 11 characters, with the captured match and a zero)
ta – If the substitution was successful then branch to label a

t label
If a s/// has done a successful substitution since the last input line was read and since the last t or T command, then branch to label; if label is omitted, branch to end of script.

`\{I,J\}’
Matches between I and J, inclusive, sequences.

Source:

http://www.unix.com/shell-programming-scripting/223047-add-0-values-replace-empty-value.html

Categories: bash, sed Tags:

JLSN – Basic Mercurial usage

April 21, 2013 Leave a comment

I have been using Subversion for a long time for version control but I wanted to learn something new. So picked Mercurial since some guys I know seem to love it. As usual I am just keeping this here for future reference. One thing I learnt was not to try to map svn commands to hg commands. I just approached this like someone who has never used a version control system before. My notes below

$pwd
/home/user/
# Copy existing repository
# Over the network use the url
$hg clone http://hg.serpentine.com/tutorial/hello

# Always a good idea to keep a copy the original repository
$hg clone hello my-hello
$cd my-hello

# Give a view of the history of changes in the repository
$hg log

# View a specific revision
$hg log -r 3
$hg log -r 1 -r 4
$hg log -r 2:4
$hg log -r 4:2

# More verbose log
$hg log -v r 3

# Get the description and content of the change.
$hg log -v -p -r 2

# Add a new line to hello.c
printf("Hello again\n");

# What does Mercurial know about the files in the repository
$hg status

# See what has changed
$hg diff
$ cd ../
$hg clone hello hello-pull

# How to pull changes in another repository(my-hello) into yours(hello-pull)
$cd hello-pull
$hg pull ../my-hello

# To pull specific changes specify the revision number or the change set number
# NB Pull does not make changes. It just tells you what has been changed.
# Update the working directory to the state it was in at any revision in the 
# history of the reposity. If no revision is specified it updates tip.
$hg update 
$hg update -r2
$hg update tip

# To pull and update tip
$hg pull -u

# To find out what revision the working directory is at
$hg parents

# Pushing changes from your repository (my-hello) 
# to another repository (hello-push)
$cd ..
$hg clone hello hello-push
$cd my-hello

# Find out what changes will be pushed to the other repository
$hg outgoing ../hello-push

# Do the actual push
$hg push

# NB. Not possible to update the working directory in the repository being pushed.
# One reason could be that someone is working on some stuff and you updating 
# their stuff will not be fun.

# To start a new project
$cd ..
$hg init myproject
$less goodbye.c
#include <stdio.h>

int main(){
    printf("Goodbye\n");
    
    return 0;
}

$mv goodbye.c myproject/
$hg add
$hg status
$hg commit -m "Initial Commit"
$hg log

Source:
Mercurial: The Definitive Guide by Bryan O’Sullivan

Also read:
http://hginit.com

Stop the Hollyweb!

April 17, 2013 Leave a comment

Stop the Hollyweb! No DRM in HTML5.

Categories: Interesting Tags:

Interesting – Python, ‘yeild’ and ‘generators’ explained

April 16, 2013 Leave a comment
Categories: Interesting, python

Twitter Bootstrap – Responsive Website Design

March 20, 2013 Leave a comment

Learning about bootstrap nice intro below

How to use Twitter Bootstrap to Create a Responsive Website Design

samba – Share files and folders on Debian machine with windows users

March 14, 2013 Leave a comment

Problem:

Needed to share a file (Thunderbird software) on my debian machine with users on windows.

Solution:
As root on debian ip 192.168.x.x
1. Install samba. (I used synaptic. YMMV)

$ apt-get install samba

2. vim /etc/samba/smb.conf
Add the following at the end of the file.

[Software]
path=”/home/user/software”
browsable = yes
public = yes

Save and close.

3. Add a samba user. This has to be an existing user on your box.

smbpasswd -a user

4. Stop and start samba

/etc/init.d/samba stop
/etc/init.d/samba start

Now on the windows machine (depending on your windows version)
In explorer
Add a network drive then browse to //192.168.x.x/software

Source:
https://www.linuxquestions.org/questions/linux-software-2/debian-to-windows-file-sharing-programs-946890/

Categories: debian Tags: ,

JLSN – Creating an Editable PDF file

February 27, 2013 Leave a comment

Problem:
I needed to create a pdf file that allows one to fill in some details, save the changes and email the changed file.

Solution:

After searching on google, I found the following instructions that worked perfectly for me.

OpenOffice.org 2 Writer – how to create a PDF form you can fill in
1. Open a new blank writer document.
2. Type a phrase to use as a label (Example: Last name)
3. View > Toolbars > Form Controls (Checked)
4. Move the cursor over the Form Control Toolbar until the tooltip shows Text Box. Click the icon.
5. Drag the cursor over the location where you want to insert the text box.
If necessary, resize it using the handles or move it while the cursor shows a plus shape.
(Optional): Right-click the text box and change options – name, submission type etc….
6. Repeat for all the fields to enter.

If you want a default value for some or all of the fields, Click the Design Mode On/Off icon on the Form Control Toolbar to toggle off the design mode, then fill in the default values for the appropriate field(s).
7. File > Save As PDF
Save it.
Open PDF document using Adobe Acrobat.

I did this on Debian Squeeze and I can fill in the pdf when using Document Viewer, xpdf and ePDFViewer do not seem to be able to allow that to work. So it works well with Document Viewer, but fails on Windows with Adobe Acrobat 9.

Looks like it is a known issue https://issues.apache.org/ooo/show_bug.cgi?id=121782 Now my problem is that 100% of the users this was intended for are on Windows and are going to use Adobe Acrobat. I guess I am going to have to use a word document after all.

After more searching
https://blogs.adobe.com/dmcmahon/2011/09/10/adobe-reader-fill-out-a-pdf-form-or-type-text-on-a-pdf-file-using-adobe-reader/

Source:
http://www.oooforum.org/forum/viewtopic.phtml?t=43073

Follow

Get every new post delivered to your Inbox.

Join 27 other followers