Krishna Logo
qa training in canada now
Divied
Call: Anusha @ 1 (877) 864-8462

 

Latest News
Home Navigation Divied
INTERVIEW Navigation Divied UNIX INTERVIEW QUESTIONS
Showing 81 - 90 of 324 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
UNIX INTERVIEW QUESTIONS
 
81How To Check The Length Of Any Line In A File?
Date Posted: 07/02/2012

 Ans: We already know how to print one line from a file which is this:
$> Sed –n '<n> p' file.txt
Where <n> is to be replaced by the actual line number that you want to print. Now once you know it, it is easy to print out the length of this line by using [WC] command with '-c' switch.
$> Sed –n '35 p' file.txt | WC –c
The above command will print the length of 35th line in the file.txt.

 
 
82How 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

 
 
83How 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

 
 
84How 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

 
 
85How 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

 
 
86How 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.

 
 
87What 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.

 
 
88What 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.

 
 
89How 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.

 
 
90What 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.

 
Showing 81 - 90 of 324 Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next
Shadow Bottom
 
 
© 2005 -