Monday, March 25, 2019


Cut Command: -
Q) What are options used in cut command ?
Ans – There are two options used in cut command.
1.       –c –> to cut character wise
2.       –f -> to cut field wise
Q)  Give third character present in all lines of the file f1 ?
Ans - $ cut –c3 f1<Enter – Key>
Q) Give third to 12th characters in all lines of the file f1 ?
Ans - $ cut –c3-12 f1<Enter – Key>
Q) Give 1st to 7th characters in all lines of the file f1 ?
Ans - $ cut –c-7 f1<Enter – Key>
Q) Give 5th character, 7th to 13th characters and then 23rd to 27th characters in all lines of a file f1 ?
Ans - $ cut –c5,7-13,23-27 f1<Enter – Key>
Q) Give 3rd to last characters of all lines for the file f1 ?
Ans - $ cut –c3- f1<Enter – Key>
Q) Give 3rd to 7th characters of 6th line of a file f1 ?
Ans - $ sed –n ‘6p’ f1 | cut –c3-7<Enter – Key>
Q)  Give third field present in all lines of the space separated file f1 ?
Ans - $ cut –d ‘ ‘ –f3 f1<Enter – Key>
Q) Give third to 12th fields in all lines of the space separated file f1 ?
Ans - $ cut –d ‘ ‘ –f3-12 f1<Enter – Key>
Q) Give 1st to 7th fields in all lines of the space separated file f1 ?
Ans - $ cut –d ‘ ‘ –f-7 f1<Enter – Key>
Q) Give 5th field, 7th to 13th fields and then 23rd to 27th fields in all lines of a space separated file f1 ?
Ans - $ cut –d ‘ ‘ –f5,7-13,23-27 f1<Enter – Key>
Q) Give 3rd to last fields of all lines for the space separated file f1 ?
Ans - $ cut –d ‘ ‘ –f3- f1<Enter – Key>
Q) Give 3rd to 7th fields of 6th line of a space separated file f1 ?
Ans - $ sed –n ‘6p’ f1 | cut –d ‘ ‘ –f3-7<Enter – Key>
Q) Write a command to cut 2nd to 4th field and 6th and 7th field from a csv file file.csv ?
Ans - $ cut –d ‘,’ –f2-4,6,7 file.csv<Enter – Key>
Q) How to get 9th and 5th columns of ls –lrt command ?
Ans - $ ls –lrt | tr –s ‘ ‘ | cut –d ‘ ‘ –f9,5<Enter – Key>
Q) Show me all directories name and their number of links ?
Ans - $ ls –ld | tr –s ‘ ‘ | cut –d ‘ ‘ –f9,2<Enter – Key>

No comments:

Post a Comment

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...