Everyday useful sed command

If you have this text file containing:

█▓▒░bondhan@optimus-prime█▓▒░ Wed Dec 22 14:00:23
/media/BONDHAN_4GB/workspace/grep_exercise/ cat grep_exercise.sh
1. Print all lines containing the string San.
2. Print all lines where the person’s first name starts with J.
3. Print all lines ending in 700.
4. Print all lines that don’t contain 834.
5. Print all lines where birthdays are in December.
6. Print all lines where the phone number is in the 408 area code.
7. Print all lines containing an uppercase letter, followed by four lowercase letters, a comma, a space, and one uppercase letter.
8. Print lines where the last name begins with K or k.
9. Print lines preceded by a line number where the salary is a six-figure number.
10. Print lines containing Lincoln or lincoln (remember that grep is insensitive to case).

If you want to append word echo “ in front of each line and add the at the end of each line, then this is the command:

sed -e ‘s/^[ \t]*/echo \”/g’ -e ‘s/\.$/\”/g’ grep_exercise.sh

The command above will search for a blank line or tab at the beginning of each line then replace with echo “ and then after -e flag the it will find at the end of each line (.$) and replace with ” (\”).

The result: Continue reading

Posted in Linux, Programming, Sed | Tagged , | Leave a comment

Sed Exercise (From “UNIX® Shells by Example Fourth EditionBy Ellie Quigley”)

To become familiar with sed (stream editor), I decided to write the answer of exercise from the book titled “UNIX® Shells by Example Fourth EditionBy Ellie Quigley”. Download here for downloading the questions and answers, or directly from your beloved shell wget http://bondhan.web.id/files/sed_exercise.tar.gz.

Suppose you have a file, containing these lines:

█▓▒░bondhan@optimus-prime█▓▒░ Tue Dec 21 16:58:22

/media/BONDHAN_4GB/workspace/sed_exercise/ cat text_file
Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300

Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500

Igor Chevsky:385-375-8395:3567 Populus Place, Caldwell, NJ 23875:6/18/68:23400

Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700

Jennifer Cowan:548-834-2348:583 Laurel Ave., Kingsville, TX 83745:10/1/35:58900

Jon DeLoach:408-253-3122:123 Park St., San Jose, CA 04086:7/25/53:85100

Continue reading

Posted in Exercise, Linux, Programming, Sed | Tagged , | Leave a comment

Organizing e-Books using Bash

To become familiar with *nix scripting, I told myself to write a small script written in bash.

The script will find certain ebooks (using keywords) then write the found results into a text file. From the found results, the script will chose if each file is one of the ebook type  that is with the extension of .pdf, .chm, .doc or you can add any other extensions. The chosen file will be executed (move or copy) to the destination folder specified. The list of the files that have been manipulated is written on a log file.

The script can also do simulation which means the script will search for the ebooks and write the ebooks on the specified target as empty files. This option is good choice for learning how this script is working.

I had to write two files for checking if it is the correct ebook or not, actually the script will be simpler if at the begining it can search the exact file using regular expression, too bad my knowledge is not that good enough :( Continue reading

Posted in Bash, Linux, Programming | Tagged , , , | Leave a comment

Install Bold-Like Theme on Curve 8320

Cannot afford to buy bold but having Curve 8320? Well this short tip might be what you are looking for :p

Here is the case, well actually this article is nothing like pimping your blackberry, I just want to share that I just successfully create a .alx file by writing it manually (actually copy and paste :d). First you need to download the original theme from here.

After you extract, some articles in the Internet is telling that you can directly click the .jad and then it will automatically install the theme. I does not work for me though, after several times clicking the .jad file and wait…nothing happen, the phone stops (seems like processing something) and for infinite time did nothing until I press the green (OK/call) or red (power) button.

Then I decided to look at the another .alx from another installer. It looks like only a description file (like xml), well then I thought why not write it manually? Continue reading

Posted in Void | Tagged , , | Leave a comment

A simple-multipurpose GNU Makefile

Since joining the current company, I usually make my own Makefile rather than using the default Makefile from eclipse. I feel that make is very powerful, just by calling make and its parameters, there you are, you get your binary in a snap. As you know, developers waste their valuable  time in compiling :d

You can download a simple project simply do nothing except compiling two files, well do nothing here is saying Hello World using standard cout. You may download the project here.

Note: You need to specify the binary filename which will be produced and the object filenames need to be linked. This is one of the weaknesses, but I think I can bear with it.

The Makefile snippet:

Continue reading

Posted in C/C++, Linux, Programming | Tagged , , | Leave a comment

Modem Haier CE100: Panggilan Telepon SMS Selalu Gagal

Di rumah untuk terkoneksi internet, saya menggunakan modem Haier CE100 unlock dengan menggunakan kartu smart. Akhir-akhir ini entah mengapa saya tidak bisa melakukan panggilan telepon atau sms melalui GUI Haier CE100 yang terinstall secara default.

Mengapa sms/telepon penting? Karena ternyata selama ini, setiap saya isi pulsa 100 rb rupiah tidak pernah sampai 1 bln hanya 20 hari bahkan 10 hari. Saya berpikir jangan-jangan selama ini tidak pernah terigistrasi internet unlimited? Dan benar, hal ini jg diamini oleh teman saya yang menggunakan smart. Jadi untuk diingat bahwa perpanjangan internet unlimited tidak secara otomatis, sehingga user harus meregistrasi ulang paket internet unlimited mereka di akhir bulan.

Beberapa hal yang telah saya lakukan untuk men-trouble shoot masalah ini:

1. Saya mengira windows yang saya gunakan bermasalah. Tentunya hal pertama yg saya lakukan adalah me-reinstall ulang program Haier CE100. Hasil: Continue reading

Posted in Void | Tagged , , | Leave a comment

Forwarding ssh socks to outside users

Here’s the scheme. My fellow friend borrowed me a tunnel to his (sort of) expensive VPS and told me to create a socks using ssh with this command:

ssh -fND localhost:6666 account@his-vps.org

After setting the proxy (using sock not http) configuration on the browser with localhost port 6666, there you go, through his VPS I can open all the websites which are blocked by the office. However this rule is only useful for connecting from localhost.

Now, how about if other users want to use my socks? Here’s what I did:

ssh -fND my_computer_ip:2222 account@his-vps.org

sudo iptables -A INPUT -p tcp -m state –state NEW –dport 2222 -i eth1 -j ACCEPT

Different with the previous one you need to configure the browser proxy setting with my my_computer_ip port 2222 NOT localhost!! Btw, the second one means that any tcp connection coming to interface eth1 port 2222 of my computer should be accepted.

Acknowledge: Thanks for root@voidnetwork.org for the VPS

Posted in Linux, Networking | 2 Comments

Beda NOR dan NAND Flash

Tentu kita tidak asing lagi dengan USB Flash donk, nah ternyata ada 2 jenis Flash yg terbanyak beredar di pasaran, dan masing2x memiliki keunggulan.

In short: Continue reading

Posted in Philosophy | Tagged , , | Leave a comment

wgetting some lectures

wget -r http://www.cse.iitb.ac.in/~cs684/spring09slides/

After sometimes I looked at the downloading processing and found video.tar.gz which is almost half gigs. Unfortunately wget doesn’t have option to limit the download file size :( , which is strange. Oh well, hopefully this video is worthy for download :p

Posted in Void | Tagged , | Leave a comment

STW (store word)

Still working on the p2020 from freescale. I found that the assembly instruction set is quite different with intel and other microcontrollers that I had been working with.

One of the instruction is:

STW (Store Word)

stw rS, d(rA)

means that you are storing the value from rS (register source) to memory location d + rA. Therefore sometimes you’ll find that the value of d can be negative.

Resource:

  1. http://pds.twi.tudelft.nl/vakken/in1200/labcourse/instruction-set/stw.html
  2. http://cache.freescale.com/files/32bit/doc/ref_manual/E500CORERM.pdf
Posted in Microprocessor, PowerPC | Tagged , , | Leave a comment