“SED”

SED- Stream Editor

It is one of the most prominent text-processing utilities on GNU/Linux. It is stream oriented and uses simple programming language. It is capable of solving complex text processing tasks with few lines of code. This easy, yet powerful utility makes GNU/Linux more interesting.

I knew the power of SED but was unaware about how to use it correctly.

I recently faced a problem when I had to run a project on a server and had to change the credentials like password there. The problem was that I had about 15 or more files in which changes were to be made. I could change the username easily by issuing the following command:

find . -type f -exec sed -i 's/<oldname>/<newname>/g' {} +

But when it came to changing password, I went into trouble because the old password was “a” and when I tried using the following on backup of the same folder.

find . -type f -exec sed -i 's/'a'/'prit'/g' {} +

The problem was that ‘a’ occured so many times in so many files at numerous places and I only wanted to replace the “a” meant for password.

('localhost','pritika','a')

So, I pinged my friend Mandeep Singh  and asked him if he could help me in the solution.

He suggested to use the following to get the file names in which ‘a’ was present in the password field:

 grep -rl ",'a')"

and then said to try this one:

 sed 's/'"'a'"'/'"'password'"'/g' somefile.php

This was working. But I had to use it for multiple files. I used for loop for that. As most of the file names were starting from t. So I chose to use it for all files starting from t.

for i in t*; do sed -i 's/'"'a'"'/'"'prit'"'/g' $i; done

And still the problem was not fully solved. There were some files where “a” was specified and not ‘a’ and the replacement didn’t take place there.

So, I used the sed command again for those left over files.

sed -i 's/'""a""'/'""prit""'/g' t_apply.php 
action.php t_index.php t_jobdetails.php

And finally the purpose was solved.

One important lesson that do test before replacing in the actual file or the replacements can affect the file badly or better you use -i.bak instead of i as it will create a backup file.

Thanks for you patience Mandeep and sorry for the delay I made in writing this blog.

Gnome Shell

It is the first time that I shifted from Unity to Gnome on ubuntu 14.04 LTS.

Here’s the Version:

Gnome

Steps of Installation:

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install gnome-shell
  4. sudo apt-get install ubuntu-gnome-desktop

After this when you restart your system, you can see the GNOME environment on your system.

gnome2-logo-text-194

The look and feel has changed!!!

But I tried changing desktop background and could see nothing in action.

A blank desktop with no icons and no right click anywhere showed me the menu for selection. At times, screen was hanging and I had to do force shutdown. So I began looking for the solution. At times, I was not able to give keyboard input also. I had to restart the system thrice or more.

After that I tried the following:

gsettings set org.gnome.settings-daemon.plugins.background active true

I could see the background changing but the right click was still not working. To resolve it:

I searched for dconf editor and opened it to enable managing desktop through file manager but it was blank and no information was available.

So, I made another trial using gnome-tweak tool:

sudo apt-get install gnome-tweak-tool

It was already installed on my system.

Just type tweak tool in top-left search option on Desktop and open it. Under Desktop, select visible icons on desktop”. I

Screenshot from 2016-06-05 11:12:51

After this I could see all icons on desktop and the problem of right click was also resolved.

Another alternative:

gsettings get org.gnome.desktop.background show-desktop-icons

If answer is false, then just set the value to true:

gsettings set org.gnome.desktop.background show-desktop-icons true

And now enjoy new desktop environment!!!!

References:

  1. Ubuntu Forums
  2. Gnome Tweak Tool
  3. Ask Ubuntu

 

The Unsaid..

index

“At every stage of life is learning and that’s what make you grow”

Recent passed days were busy rather busier than the past days. Packing up things like a traveller who is now going to end a voyage of about four years.

Yes!! these four years of degree which have finally come to an end. Time seemed to have slipped so far and the training has also ended.

When deciding about training, there are numerous thoughts in one’s mind. You are fascinated by decisions of your friends, you seek advices. I called people those whom I hadn’t or may be had rarely called in past just because I wanted a place to really show the door to things where I lack practically. Then I suddenly got an offer of stipend training not too far. But I put it to delay and neglected it. I had confusions and waited patiently so that I don’t make decisions in haste. Finally I had seen people admitting that training in TCC is a real challenge. In almost three and half years of my college life, I hadn’t before gone to that place. But it was then that I decided this would be best for me.

People were finding it difficult to swallow my decision. Even parents warned “Choose the Right Place”. Don’t worry about fee or location. Classmates used to give their advices wherever they saw me to choose a different place. “9 to 6” timings did scare initially but I was ready to start. I usually never say a “no” to anything until I have tasted it.

But today I feel proud of my decision and admire my will of joining TCC (Testing and Consultancy Cell), GNDEC as a trainee. I would say people don’t teach people at TCC. People inspire people by doing things here and I admit that I have had hesitation asking people for help at times. But now have finally got into my head asking is better than not doing things. It’s better than delaying things to point where they loose importance. I like this openness where you can ask small to big things.

The beautiful gifts that I have taken from here:

  1. Linux
  2. Latex
  3. GitHub
  4. Writing Blog

And various others…

But the above mentioned ones will go a long way with me.

In the end, I thank all GD members and specially Dr. H.S. Rai (the man behind Great Developers and one who makes sure that all members of his team grow with time.)

Gratitude 🙂

 

 

WebOctave

Weboctave provides web interface to octave i.e. the user sends the commands to a remote server, next all required computation is done on the server, and finally the user is presented with the results (text or graphics). The only requirements to use such a remote service are:

  • Internet connection
  • web browser (cookies enabled)

Weboctave’s source code is available at Source forge.

My task was to run this software. Initially after downloading the code.The installation procedure can be found in the README file of the downloaded code.

The requirements are:

  1. Mysql server
  2. Octave
  3. Linux system

After following the procedure, I tried accessing it using the browser.

The functionality offered by software:

  1. Running commands
  2. Downloading plots
  3. Defining your own functions
  4. Viewing and removing files
  5. Creating user accounts

During it’s initial run, none of the above was working.

Then I began looking into code file and seeing the directory structure. The code is mainly in php.

There are db.sql file and .css additional files.

I started from the index.php file and removed one error in the beginning quotes of php file which was missing.

The syntax used was:

    <?
        // load content
        $content->ShowContent();        
    ?>

I just changed :

    <? php
        // load content
        $content->ShowContent();        
    ?>

If you don’t want to do above, one can add this syntax in configuration file of php.

It started showing the interface in a correct way i.e. I could add account and could see entries in mysql tables. The next thing was after typing the command, I used to get “no text output” and “no graph” every time I ran the query.

So, I had to check the communication of code with the installed octave.

Later I found out  that it was due to “Permission denied”error and corrected the permissions to the folder and finally I could get the following two errors:

error

  1.  x11 display variable not set disabling the gui features
  2.  dispatch undefined

To remove the first error, I checked out display variable set in octave by using getenv(“DISPLAY”) and even tried to set it using setenv(“DISPLAY”, “:0.0”). But this didn’t solve problem.

Then, I referred my friend’s blog post and renamed octave-cli file to octave .

Firstly, I located octave-cli and then renamed using mv command. This solved my problem.

Then I had to look for dispatch function.

Why is this function required and what it does?

Loadable Function: dispatch (f, r, type):

Replaces the function f with a dispatch so that function r is called when f is called with the first argument of the named type. If the type is any then call r if no other type matches. The original function f is accessible using builtin (f, …).

If r is omitted, clear dispatch function associated with type.

If both r and type are omitted, list dispatch functions for f.

This function is obsolete in newer versions of octave and so, I looked for code of this function.

I could easily get dispatch.m file: Dispatch function file

And the next step was to add it to m folder of octave which contains the function files.

After doing so, the error was removed and I could see commands giving results and the next thing was getting black plots.

I checked my graphics_toolkit and by default  I had set it as gnuplot in the startup file.

After changing it’s toolkit and trying on gnuplot separately when the problem didn’t resolve, I just went for following as I felt there were packages that were not updated:

sudo apt-get update

sudo apt-get upgrade

This was my last refresh and I could see beautiful plots coming up on the browser.

command

gplot

But the better alternative is working on replacement of the dispatch function i.e. using classes. I have never defined classes in octave before but I have started looking for the same (Classes).

Recover removed files before commit

If you have removed your files mistakingly from current directory and have not committed the changes then here’s what I did:

  1. git status
  2.  git reset HEAD <file> to unstage the changes.
  3.  git checkout — <file> to discard changes in the working directory.

I did git reset HEAD .
git checkout — .
for all files in current working directory. Finally after “ls” you can find all your files  back.

 

One more day to go!!

Today, I worked on programs for solving simultaneous and transcendental equations. I worked on following methods: Bisection, Secant method and Newton-Raphson method. There are certain problems that need to be solved i.e. more steps being used  in particular problem and some work is pending of Newton-Raphson method and tomorrow I’ll be working on matrices.

NMCE Programs

Today, I focused on making octave programs for methods used to solve ordinary differential equations. I have made simple programs which can deal with numerical programs for civil students. Euler’s method, RK method, Adam’s Bashforth method have been implemented in form of programs. Modified Euler’s method needs more improvement in logic as I’m getting incorrect results and the next step is to make programs for solution of simultaneous and transcendental equation methods.