The Cut

Abhilasha talking to her friend: I am looking for a job change but I am worried. There is so much to study in Linux and I just don’t know what should I study in Linux ???

Friend: You will rock Abhilasha. Just go through these basic interview commands. And you will crack it.

Abhilasha: Will I be able to recall it during the interview.

Friend: Yes of course.

I will explain you the commands in a very easy manner and you will be able to recall them all. All the best girl. Let’s study now.

THE WORRIED FRIEND

Unnamed+Project

What is Cut Command?

As the name, suggest cut command is used to cut sections of text or a portion of text from a file or section of character from the lines written in the given file.

For example: Create a file name: Winner.txt

A file in linux can be created in two ways –

1.using the vi editor.
open terminal.
vi winner.txt(filename)
press i (takes you to the insert mode. You can even type, a or o)
type the content, press escape key, and type:wq.
The file is created.
2. using cat command
cat > winner.txt
type the content
control C or control D.
 Screenshot from 2018-01-07 01:14:16
1. Extract the second character from each line –

 cut -c 2 winner.txt

Output would be :

o
f

e

Screenshot from 2018-01-07 01:16:30

2. Extract the fifth character :

cut -c5 winner.txt

Output :

o
o
`Screenshot from 2018-01-07 01:18:47

Please note that now for the first line blank space would be printed as character 5.

3. Extract more than one character from a file

cut -c 8,9 winner.txt

Output :
rd
wa
ti
Screenshot from 2018-01-07 01:20:43

4. Print a range of characters you can do this like :

cut -c2-7 Winner.txt

Output :

ork ha
f you

e posi

Screenshot from 2018-01-07 01:22:20

5.Print characters from some specific position.

cut -c 3- winner.txt

Output :

rk hard to achieve your Goals.
you want to achieve something, have focus on it.
positive and love your life.

Screenshot from 2018-01-07 01:25:13

 

The Tech World

 

 

 



Leave a comment