Krishna Logo
Divied
Call: Harsha @ 571-386-2972

 

Loading
Latest News
Home Navigation Divied
INTERVIEW Navigation Divied UNIX INTERVIEW QUESTIONS
Showing 81 - 90 of 323 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
UNIX INTERVIEW QUESTIONS
 
81How To Remove The Last Line/ Trailer From A File In UNIX Script?
Date Posted: 07/02/2012

  Ans: Always remember that [Sed] switch '$' refers to the last line. So using this knowledge we can deduce the below command:
$> Sed –i '$ d' file.txt

 
 
82How To Remove Certain Lines From A File In UNIX?
Date Posted: 07/02/2012

   Ans: If you want to remove line <m> to line <n> from a given file, you can accomplish the task in the similar method shown above. Here is an example:
$> Sed –i '5, 7 d' file.txt
The above command will delete line 5 to line 7 from the file file.txt

 
 
83How To Remove The First Line / Header From A File?
Date Posted: 07/02/2012

Ans: We already know how [Sed] can be used to delete a certain line from the output – by using the’d’ switch. So if we want to delete the first line the command should be:
$> Sed '1 d' file.txt
But the issue with the above command is, it just prints out all the lines except the first line of the file on the standard output. It does not really change the file in-place. So if you want to delete the first line from the file itself, you have two options.
Either you can redirect the output of the file to some other file and then rename it back to original file like below:
$> Sed '1 d' file.txt > new_file.txt
$> my new_file.txt file.txt
Or, you can use an inbuilt [Sed] switch '–i' which changes the file in-place. See below:
$> Sed –i '1 d' file.txt

 
 
84How To Display N-th Line Of A File?
Date Posted: 07/02/2012

 Ans: The easiest way to do it will be by using [Sed] I guess. Based on what we already know about [Sed] from our previous examples, we can quickly deduce this command:
$> Sed –n '<n> p' file.txt
You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will be
$> Sed –n '4 p' test
Of course you can do it by using [head] and [tail] command as well like below:
$> head -<n> file.txt | tail -1
You need to replace <n> with the actual line number. So if you want to print the 4th line, the command will be
$> head -4 file.txt | tail -1

 
 
85How To Print/display The Last Line Of A File?
Date Posted: 07/02/2012

Ans: The easiest way is to use the [tail] command.
$> tail -1 file.txt
If you want to do it using [Sed] command, here is what you should write:
$> Sed -n '$ p' test
From our previous answer, we already know that '$' stands for the last line of the file. So '$ p' basically prints (p for print) the last line in standard output screen. '-n' switch takes [Sed] to silent mode so that [Sed] does not print anything else in the output.

 
 
86What Are The Events Done By The Kernel After A Process Is Being Swapped Out From The Main Memory
Date Posted: 07/02/2012

Ans: When Kernel swaps the process out of the primary memory, it performs the following:
Kernel decrements the Reference Count of each region of the process. If the reference count becomes zero, swaps the region out of the main memory,
Kernel allocates the space for the swapping process in the swap device,
Kernel locks the other swapping process while the current swapping operation is going on,
The Kernel saves the swap address of the region in the region table.

 
 
87What Is The Easiest Way To Store Variables And Explain?
Date Posted: 07/02/2012

Ans: The easiest way to store the values of the variables is in a 26-element array; the single-letter variable name can be used to index the array. But if the grammar is to process both variable names and values in the same stack, yacc has to be told that its stack contains a union of a double and an int, not just a double.

 
 
88How To Search Files For Lines That Match A Pattern?
Date Posted: 07/02/2012

Ans: Grep command searches for files for lines which match a pattern.
E.g. g/regular expression/p.grep will also look for lines that don’t match the pattern, when the option-V is used. Grep can be used to search several files in that case it will prefix the filename.

 
 
89What Is A Pipe And Give An Example
Date Posted: 07/02/2012

Ans: A pipe is two or more commands separated by pipe char '|'. That tells the shell to arrange for the output of the preceding command to be passed as input to the following command.
Example: ls -l | pr
The output for a command ls is the standard input of pr.
When a sequence of commands is combined using pipe, then it is called pipeline.

 
 
90What Happens When You Execute A Program
Date Posted: 07/02/2012

Ans: When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system. Each process has process context, which is everything that is unique about the state of the program you are currently running. Every time you execute a program the UNIX system does a fork, which performs a series of operations to create a process context and then execute your program in that context. The steps include the following:
Allocate a slot in the process table, a list of currently running programs kept by UNIX.
Assign a unique process identifier (PID) to the process.
ICopy the context of the parent, the process that requested the spawning of the new process.
Return the new PID to the parent process. This enables the parent process to examine or control the process directly. After the fork is complete, UNIX runs your program.

 
Showing 81 - 90 of 323 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
Shadow Bottom
 
    Courses Offered
  • Courses not available.
 
© 2005 - 2018 Krishna Training.
Designed & Developed By BitraNet