Browsing all articles in How-To’s
Aug
29

Vim: How to Copy Multiple Lines

If you are using vim as editor and you are using vim inside a pseudo-terminal such as PuTTY, you might have less trouble with copy and paste function as you can use your mouse to highlight text, copy, and paste it inside the file.

However, if you have difficulty copying multiple lines in vim without access to mouse, or in tty, you might want to utilize the command ‘v’ or ‘V’.

To yank (copy) multiple lines:

1) Place the cursor on the first position of the first line you want to yank.
2) In vim command mode, press ‘v’ (without the quotes). You will notice that the message “– VISUAL –” will appear on the lower left part of the screen. This is an indicator that you are now in ‘Visual’ mode.
3) Use your arrow keys to move the cursor to highlight the lines of texts you want to manipulate.
4) After highlighting, press the ‘y’ key to yank (copy) the highlighted lines. You will notice the message similar to “9 lines yanked” on the lower left side of the screen. This means you have successfully copied the lines and ready to be pasted!
5) Place your cursor on the line you want to insert your copied lines to and press ‘p’ to paste below the cursor, or ‘P’ to paste above the cursor.

Voila!

If you would rather cut the lines, press ‘d’ instead of ‘y’.

Aug
21

How Replace Space with Newline in Vim

In vim, you can run commands to simplify tasks. One case is to replace spaces with newline, or any character.

Inside vim, go to command mode by pressing the ESC key. Then enter the following command:

:%s/\s/\r/g

This will substitute (%s) spaces (\s) with return or newline (\r) and continue the replacement until end of line (g).

This is the command to use if you need to replace newline with spaces:

:%s/\n/\s/g

This will substitute (%s) newline (\n) with space (\s) and continue the replacement until end of line (g).

You may notice that newline and return characters are used differently and not interchangeable. This is because \r means ‘carriage return’ and if ever you had one of those typewriting classes wherein you learn how to use a typewriter (not a computer!), you will know what carriage return means. Anyway, in computing, it means the same thing, to move the cursor to the beginning of the line. Although it means almost the same, newline or \n does things differently. Newline character, or ‘line feed’, instructs the cursor to move to the next line.

So how is this relevant to the vim commands above?

When the user presses the ‘Enter’ key, the equivalent command is actually ‘CR-LF’, a combination of carriage return (CR) and line feed (LF)on Windows systems. In Linux systems, the ‘Enter’ key is just ‘LF’, it is understood that you want the cursor the start at the beginning of the line.

However, in replacing \n and \r characters in vim, these two are not interchangeable. If you need to add line feed, use the CR character, \r. If you need to remove the line feed, use the LF \n character.

Aug
19

How to Add or Remove Library Path in RHEL

In Red Hat Enterprise Linux systems, you can modify the list of library paths that is not loaded by default.

What are Linux libraries?

If you have libraries outside the common and trusted library directories such as /usr/lib, /usr/lib64, /lib, or /lib64, you can add the directory by using the ldconfig command.

If you have compiled a new set of libraries, it is placed in the /usr/local/lib directory, in most cases. We are going to use the /usr/local/lib library path, the location of our newly compiled unixODBC 2.3 libraries, that we need to check, add, or remove in our examples.

Checking if the Library Path is Loaded

To check if the directory containing your libraries are already loaded, run the following command to verify:

ldconfig -v

The command `ldconfig -v` will list all the current library paths loaded by ldconfig.

Adding a Library Path

Use the following steps to add library paths:

1. Create the file unixODBC-2.3.conf and place the directory in this file. This will serve as a container for the library path.

echo "/usr/local/lib" > /etc/ld.so.conf.d/unixODBC-2.3.conf

2. Reload the ldconfig command to update the dynamic linker.

ldconfig

3. Check if the path is now in the list of links.

ldconfig -v

You should see something like this:

     /usr/local/lib:
            libodbc.so.1 -> libodbc.so.1.0.0
            libodbcinst.so.1 -> libodbcinst.so.1.0.0
            libodbccr.so.1 -> libodbccr.so.1.0.0

Removing a Library Path

1. Remove the file unixODBC-2.3.conf.

rm -f /etc/ld.so.conf.d/unixODBC-2.3.conf

2. Reload the ldconfig command to update the dynamic linker.

ldconfig

3. Check if the path has been removed from the list of links.

ldconfig -v

Feb
3

How to Setup Raspberry Pi (Part 2)

On my previous post, I have shown the first steps on how to get the actual operating system of Raspberry Pi on an SD card. Here I will show you how to get the lean mean Raspberry Pi machine up and running.

Step 2: Attach peripherals, network and power

  1. On your RasPi board (which should be in its clear case by now), there is one (1) slot for the SD card. So I want you to place your SD card, the one where the Raspbian image was written onto, into the SD card slot. It should be snug and does not wiggle or move around.
  2. Connect your RasPi to your display device, I used our Samsung UA40EH5300 TV, by attaching the HDMI cable on your RasPi to the TV. Do not forget to change the source of your display to the HDMI port. (If you have the same model as I have, just press the Input button on the remote and select the highlighter HDMI option.)
  3. Connect the keyboard and mouse (if you want to use the GUI) to the two USB ports.
  4. Next, attach your ethernet or network patch cable to the ethernet port. Perform this step if you need your RasPi to be accessible over the network via SSH.
  5. Lastly, attach the Micro USB to the RasPi and plug the power supply in to the power outlet.
  6. Cross fingers.
  7. If everything goes well, you should see some texts running on your screen. It will eventually stop at the Setup guide. At this point, you may want to change the root password first by selecting the Change Password option. Reboot.
  8. At the next boot, you should be able to login using the user ‘pi’ and typing the password of your choice.
  9. Once you are logged in, you now have a fully working RasPi.

Congratulations!

In my next blog post, I will discuss how to setup DLNA on your RasPi for media sharing.

Jul
14

Tip: Perl Script to Archive Log Files

This is a simple Perl script I wrote to search a given directory for *.log files, tag with the current date and archive them.

#!/usr/bin/perl

$DIR=”/var/www/html/sites/logs”;
$DATE=`date +%F`;
chomp $DATE;

@log = `/usr/bin/find $DIR -type f -name “*.log” `;

#print “\nRotating $DATE\n”;

foreach $log (@log) {
chomp $log;
$new_fn=”$log”.”-”.”$DATE”;
#print “$log $new_fn\n”;
`mv “$log” “$new_fn”`;

}

@raw=`/usr/bin/find $DIR -type f -name “*$DATE*”`;

foreach $raw (@raw) {
chomp $raw;
#print “$raw\n”;
`gzip -9 $raw`;

}

EDIT:

Modified version:

#!/usr/bin/perl

$DIR=”/var/www/html/sites/logs”;
$DATE=`date +%F`;
chomp $DATE;

@log = `/usr/bin/find $DIR -type f -name “*.log” `;

#print “\nRotating $DATE\n”;

foreach $log (@log) {
chomp $log;
$new_fn=”$log”.”-”.”$DATE”;
#print “$log $new_fn\n”;
`mv “$log” “$new_fn”`;
`gzip -9 $new_fn`;

}

Powered by 1and1.comDomain Registrations starting at $9.98* Earn with Your BlogAdvertise @ PinoyTux

Search PinoyTux

Subscribe to Email Feeds

Enter Email Address:

Blog Lounge

Popular Posts

Recent Posts

Recent Comments

Site Stats