Basic sed tricks

  1. What is sed? - sed is stream editor, a Unix tool for working with streams of text data. See the awful truth about sed.
  2. How do you substitute strings with sed? - Use ’s/old/new’ command, so sed ’s/hello/goodbye/’ would substitute the occurrence of the word hello to goodbye.
  3. How do you inject text with sed? - & in the substitution string defines the pattern found in the search string. As an example, here’s us trying to find a word ‘hello’ and replacing it with ‘hello and how are you’:
         echo ‘hello there’ | sed ’s/^hello/& and how are you/’
  4. Can I find several patterns and refer to them in the replacement string? - Yes, use (pattern) and then refer to your patterns as \1, \2, \3 and so on.
  5. If the string is ‘old old old’ and I run ’s/old/new’, I get ‘new old old’ as the result. I need ‘new new new‘. - You forgot the global modifier, which would replace every occurrence of the pattern with the substitution. ’s/old/new/g‘ will work.
  6. But I want ‘old old new’ from the previous example. - Just use the numeric modifier saying you want the third occurrence to be replaced. ’s/old/new/3‘ will work.
  7. I wrote a rather complex sed script. How do I save and run it? - Assuming that your file is named myscript1.sed, you can invoke sed -f myscript1.sed.
  8. How do I delete trailing whitespaces from each line? - sed ’s/[ \t]*$//’ Here we’re replacing any occurrence of a space or a tab with nothing. Check sed one-liners for more examples.
  9. How do you print just a few first lines of the file? - sed 1q will give you just the first line, sed 10q the first 10 lines.
  10. How do you replace a pattern only if it’s found, so that it’s executed faster? - Nest the replacement statement: sed ‘/old/ s/old/new/g’ file.txt
Posted in Unix/Linux | Leave a comment

40 student interview questions from NetApp

  1. Why did you choose your major?
  2. Why did you choose your school?
  3. Describe a recent leadership experience.
  4. Which courses have you enjoyed the most? The least? Why?
  5. What is your GPA?
  6. If you could do so, how would you plan your education differently?
  7. Read More »

Posted in General | 1 Comment

Programming phone screen questions

kSquared at GameDev community forums posted a list of phone screen questions from Google, with some answers that he attempted. You’ll have to head to GameDev to read the answers, but here’s the list of questions to ponder:

  1. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?
  2. How would you find out if a machine’s stack grows up or down in memory?
  3. Explain a database in three sentences to your eight-year-old nephew.
  4. How many gas stations would you say there are in the United States?
  5. How many golf balls can fit in a school bus?
  6. How much should you charge to wash all the windows in San Francisco?
  7. Read More »

Posted in Database, General, Puzzles | 18 Comments

Linux network administrator questions

A pretty funny story - someone was offered a test of basic Linux questions for a junior network administrator position, and figured out that the best way to impress the future employer with good answers is to post the list on UbuntuForums. Good idea, right? That’s where all the Linux experts hang out. Unfortunately, that’s where the employer hung out as well:

It didn’t seem to me that I was asking too much for people to use mailing lists, forums, IRC whatever to compile the answers themselves. I actually expected to see some questions show up on forums but I didn’t expect someone to paste the entire thing and expect the forum users to do all the work that would qualify you for an interview. I think at this point you could save us all some time and not turn the answers back in, I already have the information I need on your answers.

Anyway, the list has been made public, so enjoy:

  1. Give an example of set of shell commands that will give you the number of files in a directory
  2. How do you tell what process has a TCP port open in Linux
  3. On a Red Hat Linux Variant how do you control whether a service starts when the system boots
  4. How do you tell the amount of free disk space left on a volume
  5. Give an example of a set of shell commands to tell how many times “bob” has logged on to the system this month
  6. Give an example of a recursively copying a directory from one location to another.
  7. How do you modify the IP and Net mask of a system running a Red Hat Variant of Linux
  8. Read More »

Posted in Networking, Unix/Linux | 7 Comments

Basic programming questions

  1. Design a data structure such that given a stream of numbers, you can find the maximum of the numbers at any point and also all the numbers.
  2. Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions.
  3. Find the common ancestor of two given nodes in a binary tree, how do you exploit the properties of a given BST for the same problem.
  4. You’re given a function getsort(data) that sorts the data given. The function sorts in place and does not use any extra memory. How do you validate the function with respect to 1) it sorts 2) it does not use extra memory
  5. Explain the Traveling Salesman problem? What is an NP-complete problem? What is the Hamiltonian cycle problem?
  6. Find out the least common ancestor in a binary tree.
Posted in General | 3 Comments

Linux command line Q&A

  1. You need to see the last fifteen lines of the files dog, cat and horse. What command should you use?
    tail -15 dog cat horse
    The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.
  2. Who owns the data dictionary?
    The SYS user owns the data dictionary. The SYS and SYSTEM users are created when the database is created.
    Read More »

Posted in Unix/Linux | 2 Comments

SQL interview questions and answers

  1. What are two methods of retrieving SQL?
  2. What cursor type do you use to retrieve multiple recordsets?
  3. What is the difference between a "where" clause and a "having" clause? - "Where" is a kind of restiriction statement. You use where clause to restrict all the data from DB.Where clause is using before result retrieving. But Having clause is using after retrieving the data.Having clause is a kind of filtering command.
  4. What is the basic form of a SQL statement to read data out of a table? The basic form to read data out of table is ‘SELECT * FROM table_name; ‘ An answer: ‘SELECT * FROM table_name WHERE xyz= ‘whatever’;’ cannot be called basic form because of WHERE clause.
    Read More »

Posted in Database, Windows | 3 Comments

Java interview questions and answers

Describe what happens when an object is created in Java?

Several things happen in a particular order to ensure the object is constructed properly:
1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implementation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its uppercase. This process continues until the constructor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

Read More »

Posted in Java | 2 Comments

WinRunner question encyclopedia with answers

176 questions, so warm up that fireplace.

  1. Explain WinRunner testing process? - a) WinRunner testing process involves six main stages
    i.Create GUI Map File so that WinRunner can recognize the GUI objects in the application being tested
    ii.Create test scripts by recording, programming, or a combination of both. While recording tests, insert checkpoints where you want to check the response of the application being tested.
    iii.Debug Test: run tests in Debug mode to make sure they run smoothly
    iv.Run Tests: run tests in Verify mode to test your application.
    v.View Results: determines the success or failure of the tests.
    vi.Report Defects: If a test run fails due to a defect in the application being tested, you can report information about the defect directly from the Test Results window.
  2. Read More »

Posted in Testing | Leave a comment

Java threads question set

  1. Do I need to use synchronized on setValue(int)? - It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.
  2. Do I need to use synchronized on setValue(int)? - It depends whether the method affects method local variables, class static or instance variables. If only method local variables are changed, the value is said to be confined by the method and is not prone to threading issues.
  3. Read More »

Posted in Java | 2 Comments

Unix admin questions

  1. How do you list the files in an UNIX directory while also showing hidden files?
  2. How do you execute a UNIX command in the background?
  3. What UNIX command will control the default file permissions when files are created?
  4. Explain the read, write, and execute permissions on a UNIX directory.
  5. What is the difference between a soft link and a hard link?
  6. Give the command to display space usage on the UNIX file system.
  7. Explain iostat, vmstat and netstat.
  8. How would you change all occurrences of a value using VI?
  9. Give two UNIX kernel parameters that effect an Oracle install
  10. Briefly, how do you install Oracle software on UNIX.
Posted in Unix/Linux | 12 Comments

Hiring an IT guy - questions to ask

This is an aggregated list of questions discussed for hiring an IT guy for your organization at SpiceWorks community forum. Check out their discussion, and description of what question are good and which ones are not that good.

  1. What port does telnet use?
  2. What is SMTP?
  3. How would you troubleshoot a printer?
  4. How does traceroute work?
  5. Walk me through everything that happens in the network from the moment you punch in www.google.com in the address bar to when the browser displays the page?
  6. Can you work this weekend?
  7. Read More »

Posted in General, Unix/Linux, Windows | 11 Comments