Unix interview questions and answers

1. Write a command to display your name 100 times.


The Yes utility can be used to repeatedly output a line with the specified string or 'y'.
yes <your_name> | head -100

2. Write a command to display the first 10 characters from each line of a file?

cut -c -10 filename

3. The fields in each line are delimited by comma. Write a command to display third field from each line of a file?


cut -d',' -f2 filename

4. Write a command to print the fields from 10 to 20 from each line of a file?

cut -d',' -f10-20 filename

5. Write a command to print the first 5 fields from each line?

cut -d',' -f-5 filename

6. By default the cut command displays the entire line if there is no delimiter in it. Which cut option is used to suppress these kind of lines?

The -s option is used to suppress the lines that do not contain the delimiter.

7. Write a command to replace the word "bad" with "good" in file?

sed s/bad/good/ < filename

8. Write a command to replace the word "bad" with "good" globally in a file?

sed s/bad/good/g < filename

9. Write a command to replace the word "apple" with "(apple)" in a file?

sed s/apple/(&)/ < filename

10. Write a command to switch the two consecutive words "apple" and "mango" in a file?

sed 's/\(apple\) \(mango\)/\2 \1/' < filename

11. Write a command to display the characters from 10 to 20 from each line of a file?


cut -c 10-20 filena








Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post