0% found this document useful (0 votes)
221 views

Unix ETL Interview Questions

The document provides examples of Unix/Linux commands for manipulating text files and displaying system information. It includes commands for selecting portions of files, modifying file contents, getting system details, finding and filtering files. A variety of commands are demonstrated for tasks like extracting parts of lines, counting lines, changing case, joining files, sorting output.

Uploaded by

dilip_thimiri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
221 views

Unix ETL Interview Questions

The document provides examples of Unix/Linux commands for manipulating text files and displaying system information. It includes commands for selecting portions of files, modifying file contents, getting system details, finding and filtering files. A variety of commands are demonstrated for tasks like extracting parts of lines, counting lines, changing case, joining files, sorting output.

Uploaded by

dilip_thimiri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

[1] display 10th line of a file:

head -10 filename |tail -1

[2] remove the header of the file ?

sed -i ‘1’ filename


Macos: sed -i ‘1’ .bk filename

[3] remove the footer from the file ?

sed -i ‘$d’ filename

[4] command to find the length of a line in a file ?

sed -i ‘$d’ filename

[5] find the length of 10th line in a file ?

sed -n ‘10p’ filename|wc -c

[6] get the nth word of aline ?

Cut -f<n> -d’’

[7] rverse a string ?

Echo “pavan” | rev

[8] get the last word from a line in unix file ?

Echo “unix is good” |rev|cut -f1 -d’’|rev

[9] replace the nth line in a file with a newline

Sed -I’’ ‘10 d’ filename


# d stands for delete sed -I ‘’ ‘10’ new inserted line’
# I stands for insert

[10] check if the last command was successful

Echo $?

[11] command to list all the links from a directory ?


Ls -lrt |grep “^|”

[12] find the operating system you are running ?


Uname -a

[13] create a readonly file


touch filename
chmod 400 filename

[14] how do you see command line history


History

[15] rename the files in a directory with _new as suffix ?

ls -lrt |grep ‘^-‘|awk ‘{print “mv “$9 “$9”.ew”}’|sh

[16] convert string from lower case to upper case

Echo “apple” |tr[-z][A-Z]


Echo “apple” | ‘[:lower:]’ ‘[:upper:]’

[16] convert a string to initcap

echo apple | awk ‘{print toupper(substr($1,1,1))


tolower(substr($1,2))}’

[17] redirect the putput of date command to multiple files

ls -a | grep ‘^\.’

[18] list the hidden files in current directory

Date | tee -a file1 file2 file3

[19] make an existing file empty ?

cat /dev/null > filename

[20] remove the first number on 10th line in file


????

[21] join -v : outputs only matched lines between two files


Join -a: in addition to the matched lines, this will output unmatched lines also

[22] display from the 5th character to the end of the line

Cut -c 5- filename

[23] display all the files in current directory sorted by size

Ls -l grep ‘^-‘

[24] display first 10 characters from each line of a file

Cut -c -10 filename

[25] command to remove the first number on all lines that start with @

Sed ‘\,^@,s/[0-9][0-9]*//’ <filename

[26] print filenames in a directory that has the word term

grep -l term *

[27] total number of lines in a file ?

wc -l filename

[28] duplicate empty lines in a file ?

sed ‘/^$/ p’ < filename

[29] iostat, vmstat, netstat

Iostat: reports on terminal, disk and tape i/o activity

Vmstat: reports on virtual memory statistics for processes, disk, tape and cpu activity

Netstat: reports on the contents of network data structures

[30] write contents of 3 files into a single file ?

Cat file1 file2 file3 > file

[31] display the fields in a text file in reverse order ?


awk 'BEGIN {ORS=""} { for (i=NF;i>0;i--) print $i," ";print "\n"}' diliptest

[32] command to find the sum of bytes of all files in the directory ?

ls -l | grep ‘^-‘ | awk ‘BEGIN {sum=0} {sum = sum + $5} END {print sum}’
ls -ltr |grep '^-'| awk 'BEGIN {sum=0} {sum = sum + $5} END {print
sum}'
[33] command to print the lines which end with the word “end” ?

Grep ‘end$’ filename

ls -lrt |grep '^-'|awk '{print $5}'|sort -u|tail -5

[35] remove first 10 lines of a file ?


Sed ‘1,10 d’ < filename

[36] command to duplicate each line in a file

Sed ‘p’ <filename

[37] remove blank lines in a file ?


Grep -v ‘^$’ filename > new_filename

[38] display the processes that were run by yoir username ?

Ps -aef |grep username

[39] display all the files recursively with path under current
directory ?

Find . -depth -print

[40] find zero bytes size files in the current directory ?

find -size 0 -type f


[41] write a command to display the third and fifth character from
each line of a file?

Cut -c 3,5 filename

[42] command to print the fields from 10th to the nd of the line.
The fields in the line are delimited by a comma ?

Cut -d’,’ -f10- filename

[43] replace the word “GUN” with “PEN” in the first 100 lines of a
file ?

Sed ‘1,100 s/GUN/PEN/’ < filename

[44] command to display the lines that do not contain the word
“BLR”?

Grep -v BLR filename

[45] print the squares of numbers from 1 to 10 using awk


command ?

awk ‘BEGIN {for (i=1;i<=10;i++){print “square of”, i, “is”, i*i;}}’

[46] display the files in the dorectory by size ?


ls -l |grep ‘^-’ |sort -nr -k 5

[47]

You might also like