tag:blogger.com,1999:blog-77346369145160913372024-03-19T20:33:00.890-07:00Tips and TricksThis blog shall contain all the tips in using unix, windows, linux, programming tricks in perl, c++, scripting like awk, sed and etc.
This shall be consider as a technical blog.Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-7734636914516091337.post-81518612130676922702013-12-18T22:18:00.004-08:002013-12-18T22:22:57.068-08:00How to mount a directory from Windows to VirtualBox?<span style="color: white;"><span style="font-family: Verdana,sans-serif;"><u><b>Pre-requisite:</b></u></span></span><br />
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">You must have installed the "Guest Additions" before you can configure this drive mounting.</span></span><br />
<span style="color: white;"><span style="font-family: Verdana,sans-serif;"><br /></span></span>
<br />
<div>
<ol style="font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</ol>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">1. From the <b>Devices</b> menu, choose <b>Shared Folders…</b> and add any folder or drive. Make sure that the <b>Make Permanent</b> checkbox is ticked. For example, add C<b>:\VirtualBox</b> with the name <b>VirtualBox</b>. </span></span></div>
<div>
</div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">2. </span><span style="font-family: Verdana,sans-serif;">Create the directory to mount the shared folder on:</span></span></div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;"> - </span><span style="font-family: Verdana,sans-serif;">mkdir /home/alexy/shared</span></span></div>
<div>
</div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">3. </span><span style="font-family: Verdana,sans-serif;">Mount the directory</span></span></div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;"> - </span><span style="font-family: Verdana,sans-serif;">sudo mount -t vboxsf VirtualBox /home/alexy/shared</span></span></div>
<div>
</div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">4. </span><span style="font-family: Verdana,sans-serif;">To mount this every time linux boots, edit the file <b>/etc/rc.local</b> and put the following line at the start:
</span><span style="font-family: Verdana,sans-serif;"> </span></span></div>
<div>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;"> - sudo mount -t vboxsf Linux /home/alexy/shared</span></span></div>
<div>
<ol style="font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><span style="color: white;"> </span></ol>
<span style="color: white;"><span style="font-family: Verdana,sans-serif;">
</span></span>
<br />
<ol style="font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</ol>
<span style="color: white;"><br /></span></div>
Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-74574111941102225092012-11-11T22:33:00.005-08:002012-11-11T22:37:16.594-08:00Run a Process in the Foreground or the Background To run a process in the background:<br />
<b>[command] &</b><br />
<br />
To suspend a foreground process and place it in the background, use the following steps:<br />
<ol>
<li>Press <b>CTRL+Z</b></li>
<li>Enter: <b>bg</b> </li>
</ol>
<br />
To bring this background process to the foreground again,<br />
<ol>
<li>enter:
<b>fg</b></li>
</ol>
Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-69930721402256440292012-11-11T21:19:00.001-08:002012-11-11T22:32:20.783-08:00How to customize BASH profile?If you wanted to customize your .profile, .bashrc or .bash_profile, visit this link, awesome references:<br />
<br />
<a href="http://stefaanlippens.net/my_bashrc_aliases_profile_and_other_stuff">http://stefaanlippens.net/my_bashrc_aliases_profile_and_other_stuff</a><br />
<br />
or<br />
<br />
<a href="http://www.linuxfromscratch.org/blfs/view/6.3/postlfs/profile.html">http://www.linuxfromscratch.org/blfs/view/6.3/postlfs/profile.html</a><br />
<br />
<br />
Changing directory colors:<br />
<a href="http://www.geekgumbo.com/2011/11/04/changing-the-directory-color-in-the-bash-shell/">http://www.geekgumbo.com/2011/11/04/changing-the-directory-color-in-the-bash-shell/</a><br />
<br />
<br />Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-24749839212933742052012-07-02T20:30:00.005-07:002012-07-02T20:32:00.017-07:00How to use vlookup for microsoft Excel?Wondering how to use vlookup to search for a value?<br />
<br />
Scenario 1:<br />
Search a target cell to find out the existance from another column.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmoKGmza0ZxkWW-21yCu_D2A_8itjksS8RMZGqWnQLbO7l_jeYNZkYhr_m6oZksGMVM9upea3D0kixFfRCyvqW5EyEKiQetyvyA_R8vEqGI-8PfmQ2_9PgALXGieKwFJhDD6EbyltQjI/s1600/vlookup_how_to.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="158" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmoKGmza0ZxkWW-21yCu_D2A_8itjksS8RMZGqWnQLbO7l_jeYNZkYhr_m6oZksGMVM9upea3D0kixFfRCyvqW5EyEKiQetyvyA_R8vEqGI-8PfmQ2_9PgALXGieKwFJhDD6EbyltQjI/s320/vlookup_how_to.jpg" width="320" /></a></div>
<br />
In the example above, we use the formula<br />
<br />
=VLOOKUP(D3,B:B,1,FALSE)<br />
<br />
we are searching cell D3 ('C') against column B (B:B), if exist, return value from B#, FALSE is to find exact match.<br />
<br />
<br />
Scenario 2:<br />
Search a target cell E8 ('D') against column B8:C10, if exist, return the value from column C.<br />
<br />
=abs(h8-f8) to get the differences. ABS value of 0 means E9 value of 5 equivalent to B9 value of 5.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht_8aW5QUQ3KBwVmC-qTtxddTowNY6V1MJf1Hqq6DoSwRk21TpVIoPe72sg18rmtRDNQdl6QOUJLRnLrGacxHBbFNVBJzqAA5UafE5cq7OdIvvqebLH1fI5XbHT2A4RWaIhRsJt1brBRo/s1600/vlookup_how_to_02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="106" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht_8aW5QUQ3KBwVmC-qTtxddTowNY6V1MJf1Hqq6DoSwRk21TpVIoPe72sg18rmtRDNQdl6QOUJLRnLrGacxHBbFNVBJzqAA5UafE5cq7OdIvvqebLH1fI5XbHT2A4RWaIhRsJt1brBRo/s400/vlookup_how_to_02.jpg" width="400" /></a></div>
<br />Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-17202531956913235422010-10-18T00:42:00.000-07:002010-10-18T00:51:36.123-07:00How to customize PS1 prompt in BASH?<div>Edit your .bashrc</div><div><br /></div>export PS1="[\u@\w]\n>"<br /><br /><div>output:</div><div><div><div>[ubuntu@~/temp]</div><div>></div></div><div><br /></div><br /><br />Relevant info: <a href="http://www.understudy.net/custom.html#Korn">http://www.understudy.net/custom.html#Korn</a></div>Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-85088487506660598512010-10-18T00:39:00.000-07:002010-10-18T00:42:21.702-07:00How to customize PS1 prompt in KSH?eg: <br /><br />>[/current/dir] > <br />> <br />>I'd like it to be: <br />>[/current/dir] <br /><br />edit your .profile<br /><br />export PS1=[`hostname`:'$PWD]^V^J<br />>'<br />where ^V is control-V and ^J is control-J to accomplish this.Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-36432728109686318292010-05-03T19:07:00.000-07:002010-05-03T19:09:59.121-07:00How to replace ^M in unix to nothing?If you saw a lot of ^M character in your code, reason being is ^M is the character in DOS if you create the file in Windows.<br /><br />If you transfer the DOS file into unix, you will see lots of ^M in your file and it is very irritating indeed.<br /><br />You can do a simple magic in vi by<br /><br />:%s/[crtl-v ctrl-m//g<br /><br />meaning,<br />%s - substitute<br />[ctrl-v ctrl-m] - create the ^M character<br />// - empty<br />g - replace globallyAlex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-75220497117906378082009-07-08T20:20:00.001-07:002009-07-08T20:35:21.313-07:00How to view file size/details from ls command in unix?I always find it difficult to digest the filesize from the ls -al command. For instance, after ls -al, the output give me filesize in bytes.<br /><br />Gosh, then I have to start calculating it by taking last 4 digits, slowly count upwards like 1K, 10K, 100K, 1MB, 10MB, 100MB and so on so forth.<br /><br />For instance:<br /><br />this output:<br />-rw-r--r-- 1 walrus dba 137207094 Jul 8 23:12 config.2008032519.s<br /><br />137207094 is how much?<br /><br />going with my method of counting upwards, it gives me 137MB roughly.<br /><br />Is it correct? WRONG. Hell wrong<br /><br />The above is bits only. Bear in mind, 1 KB = 1024 bits, 1 MB = 1024 KB and so on so forth<br /><br />[ <a href="http://www.smartftp.com/support/kb/bits-bytes-mega-giga-tera-f53.html">Source </a>]<br />1 bit = a 1 or 0 (b)<br />4 bits = 1 nybble (?)<br />8 bits = 1 byte (B)<br />1024 bytes = 1 Kilobyte (KB)<br />1024 Kilobytes = 1 Megabyte (MB)<br />1024 Megabytes = 1 Gigabyte (GB)<br />1024 Gigabytes = 1 Terabyte (TB)<br /><br />The correct calculation is 137207094 / 1024 (bits) / 1024 (KB) = 130.8 MB<br /><br />Starting in Solaris 10, we have a new option in ls command.<br /><br /> : /u01/apps/WatchMark/FlexPM/classic/vendor/Lucent/ECP/ftpIN/in>uname -a<br />SunOS lxserver 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Fire-V445<br /><br /><span style="font-weight: bold;">ANCIENT WAY:</span><br />ls -al<br />total 270388<br />drwxr-xr-x 2 walrus dba 1024 Jul 8 23:14 .<br />drwxr-xr-x 11 walrus dba 512 Jun 17 01:49 ..<br />-rw-r--r-- 1 walrus dba 137207094 Jul 8 23:12 config.2008032519.s<br />-rw-r--r-- 1 walrus dba 451989 Jul 8 23:12 config.2008032519.split0.bz<br /><br />cons: hard to read filesize and output distorted<br /><br /><span style="font-weight: bold;">NEW WAY:</span><br />ls -al<span style="font-weight: bold; color: rgb(255, 0, 0);">h</span><br />total 269060<br />drwxr-xr-x 2 flexpm dba 1.0K Jul 8 23:12 .<br />drwxr-xr-x 11 flexpm dba 512 Jun 17 01:49 ..<br />-rw-r--r-- 1 flexpm dba 131M Jul 8 23:12 config.2008032519.s<br />-rw-r--r-- 1 flexpm dba 441K Jul 8 23:12 config.2008032519.split0.sm.gz<br /><br /><span style="font-weight: bold;">pros:</span><br />- more readable format in terms of file size<br />- contents are properly aligned.<br /><br /><span style="font-weight: bold;">cons: </span><br />- need to type extra 'h' at the end of ls commandAlex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-1023675629816897372009-07-08T20:10:00.000-07:002009-07-08T20:14:27.301-07:00How to use regular expression (regex) in grep or vi?How to use regular expression (regex) in grep or vi?<br /><br />If you need to search for a pattern of "string" or "character" in a file / many files, you will need to use regular expression (regex) either in vi editor or in grep command. But how? See below:<br /><br /><span style="font-weight: bold;">using vi:</span><br />- press '/' for searching<br />- for instance, i wanted to search for CL000, CL001, CL002, ie: the pattern is CLXXX follow by digit.<br />- syntax:<br />/^CL[0-9]* <press><br /><br />^ - start of pattern<br />* - zero or more digit<br /><br /><span style="font-weight: bold;">using unix grep command:</span><br />- grep CL[0-9] <filename>Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-43830374147257281732009-06-09T02:14:00.000-07:002009-06-09T02:17:46.045-07:00How to change oracle user password?Question: How to change oracle user password?<br /><br />Answer:<br /><p>The syntax is:</p> <blockquote class="definition"> <p>alter user <i>[user_name]<user_name></user_name></i> identified by <i>[new_password]<new_password></new_password></i>;</p> </blockquote> <p><i>user_name</i> is the user whose password you wish to change.</p> <p><i>new_password</i> is the new password to assign.</p>For eg:<br />I wanted to update system user password to helloworld<br /><br />SQL> alter user system identified by helloworld;<br /><br />User altered.Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-21701856327133471152009-05-26T20:41:00.000-07:002009-05-26T20:45:00.338-07:00How to find out the IP or machine full name in your networkHow to find out the machine IP or full address name that reside in your network?<br /><br />Answer: Use 'traceroute' command in unix<br /><br />For eg: You wanted to find a machine call "walrus" in your network<br /><br /> : /home/LX>traceroute walrus<br />traceroute to walrus.kl.lxcorp.com (10.101.110.74), 30 hops max, 40 byte packets<br /> 1 walrus.kl.lxcorp.com (10.101.110.74) 1.168 ms 0.373 ms 0.230 ms<br /><br />machine IP: 10.101.110.74<br />machine name: walrus.kl.lxcorp.comAlex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-56291863614797158202009-04-12T22:40:00.000-07:002009-04-12T22:43:16.636-07:00How to find out machine specification in Unix?Use 'uname -a' command<br /><br /> : /etc>uname -a<br /><span style="font-weight: bold;">SunOS</span> <span style="font-weight: bold; color: rgb(255, 0, 0);">shark</span><span style="color: rgb(255, 0, 0);"> </span><span style="font-weight: bold; color: rgb(153, 51, 153);">5.8</span> Generic_117350-59 sun4u <span style="font-weight: bold; color: rgb(51, 204, 0);">sparc</span> SUNW,Sun-Fire-V440<br /><br /><span style="font-weight: bold;">SunOS - machine's OS</span><br /><br /><span style="font-weight: bold; color: rgb(255, 0, 0);">shark</span><span style="color: rgb(255, 0, 0);"></span> - machine hostname<br /><br /><span style="font-weight: bold; color: rgb(153, 51, 153);">5.8</span> - SunOS version (Solaris 5.8 means Solaris 8)<br /><br /><span style="font-weight: bold; color: rgb(51, 204, 0);">sparc</span> - machine typeAlex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-41480778105803550002009-04-12T22:38:00.001-07:002009-04-12T22:40:14.001-07:00How to check machine IP in Unix?Use the command 'ifconfig -a'<br /><br /> : /etc>ifconfig -a<br />lo0: flags=1000849<up,loopback,running,multicast,ipv4> mtu 8232 index 1<br /> inet 127.0.0.1 netmask ff000000<br />ce0: flags=1000843<up,broadcast,running,multicast,ipv4> mtu 1500 index 2<br /> inet <span style="font-weight: bold; color: rgb(255, 0, 0);">9.100.90.140</span> netmask fffffe00 broadcast 9.100.90.255<br /><br /><br />The highlighted IP (<span style="font-weight: bold; color: rgb(255, 0, 0);">9.100.90.140</span>) above is the IP of the machine.Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-33255900752396652482009-03-18T22:12:00.000-07:002012-12-11T19:55:54.380-08:00CTAGS Tips and CommandRun vim (full path /usr/misc/bin/vim)<br />
Type :tj <definition> (Example: :tj api_Timer::clear, choose a number)<br />You are there!<br />Tips<br /><br />:tj[ump] <definition> (or move your cursor to it and press "g Cltr+]"*)<br />Jump to the tag directly when there is only one match<br /><br />:tn[ext]<br />Jump to next matching tag<br /><br />:tp[revious]<br />Jump to previous matching tag<br /><br />:tf[irst]<br />Jump to first matching tag<br /><br />:tl[ast]<br />Jump to last matching tag<br /><br />:po[p] (or Ctrl+T)<br />Jump to older entry in tag stack<br /><br />:ta[g]<br />Jump to newer entry in tag stack<br /><br />:tags<br />Show the contents of the tag stack. The active entry is marked with a '>'<br /><br />:tj /^get<br />Lists all the tags that starts with "get"<br /><br />:tj /norm<br />Lists all the tags that contain "norm", including "id_norm"<br /><br />:ts</definition></definition><br />
<definition><definition>List all of the definitions of the last tag<br /><br />Notes<br />*By default, Cltr+] is escape character for telnet. You can disable it through<br />Windows DOS: telnet -e '' <hostname> (two single quote ')<br />Unix: telnet -E <hostname><br />You should use dtterm (/usr/dt/bin/dtterm) to enable vim to support color mode</hostname></hostname></definition></definition>Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-34121190050250678422009-03-18T20:14:00.000-07:002012-12-11T19:47:31.465-08:00How To Generate CTAGS and Configure It To Use With VIM?Many of you wondering how to generate ctags and configure it to use with Vim? Here, you at the right place.<br /><br />What is ctags?<br /><br />According to <a href="http://ctags.sourceforge.net/whatis.html">ctags sourceforge</a>.<br />
<strong></strong><br />
<blockquote>
<strong>Ctags</strong> generates an index (or <i>tag</i>) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A <i>tag</i> signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object). <br />
Tag generation is supported for the following languages: <br />
<blockquote>
<em>Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++, COBOL, Eiffel, Fortran, Java, Lisp, Lua, Make, Pascal, Perl, PHP, Python, REXX, Ruby, S-Lang, Scheme, Tcl, Vim, and YACC.</em></blockquote>
</blockquote>
Below is 6 (six) simple steps to generate the ctags and use it with your vim.<br />
<br />
Precondition:<br />
- you need to have unix<br />
- you need to have vim<br />
<br />
Notes: you can generate ctags to use in windows but I haven't tried that before.<br />
<br />
1. Download the ctags source from<br />
<br />
http://www.sunfreeware.com/<br />
http://ctags.sourceforge.net/<br />
<br />
I'm using ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/ctags-5.7.tar.gz<br />
<br />
2. gunzip and untar it.<br />
<br />
3. run ./configure<br />
<br />
4. run make<br />
<br />
if 'make' does not exist in global environment. Search for it by<br />
find / -name make 2>/dev/null<br />
<br />
[/gateways/yapywa/ctags/ctags-5.7]<br />
12:37:35 > /usr/ccs/bin/make<br />
<br />
--> after make you will see .C get compile and with .o output file.<br />
<br />
5. cd to $HOME directory<br />
<br />
6. Generate the tags<br />
<br />
ctags -f --recurse --langmap= --languages= --verbose<br />
<br />
[/gateways/yapywa]<br />
12:37:35 ><br />
/gateways/yapywa/ctags/ctags-5.7/ctags -f tags --recurse --langmap=C++:.C.h.c.cpp.hpp --languages=C++ --extra=+q --fields=+i --verbose /gateways/yapywa/ALU_CORE<br />
<br />
7. SET CTAGS in VIM under .vimrc<br />
<br />
se tags=/home/yapywa/tagsAlex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0tag:blogger.com,1999:blog-7734636914516091337.post-35350147237403498002009-03-18T19:53:00.000-07:002009-03-18T19:56:52.059-07:00How to capture Unix console screen output?Many of you might want to capture the screen output of the unix console for references later or wanted to show the output to another counterpart.<br /><br />This command is particularly useful in 2 scenarios:<br /><br />1. During a training, where instructor do a demo using the endless list of command that you have difficulty to remember and jotting down.<br /><br />At many instances, even you can jot down the command you might not even able to remember what is the output of the command.<br /><br />Put it this way, many of us, learn from example. Hence being able to capture the screen output is very important.<br /><br />2. If you are a student and you need to show your program output to your lecturer. Use this command.<br /><br />THE COMMAND IS:<br /><br />script <filename>[filename]<br /><br />CTRL+D to exit the script command<br /><br />=========== For Instance =========<br />$ script script.out<br />Script started, file is script.out<br />$ date<br />Tue Mar 17 17:04:07 SGT 2009<br />$ time<br /><br />real 0m0.00s<br />user 0m0.00s<br />sys 0m0.00s<br />$ ^D<br />Script done, file is script.out<br /><br /><br />$ cat script.out<br />Script started on Tue Mar 17 17:04:03 2009<br />$ date<br />Tue Mar 17 17:04:07 SGT 2009<br />$ time<br /><br />real 0m0.00s<br />user 0m0.00s<br />sys 0m0.00s<br />$ ^D<br /><br />script done on Tue Mar 17 17:04:11 2009<br />$<br /><br />So simple, right ......</filename>Alex Yaphttp://www.blogger.com/profile/01694896714160998705noreply@blogger.com0