As we know about cut command is used to cut particular text from a line. In windows we can done this by simply clicking or direct shortcuts but in Linux we have to use commands to perform certain actions. In this tutorial we have going to explain various cut commands and for that we have created a file name new.txt by running following command :
Just like above command now we can extract 9 characters from beginning of line. For thatyou have to run this command :
As you can see, in this command only first field of each line display, if you need to display multiple fields then check next commands.
Code:
$ cat new.txt
Lets creating a file and used this content in it.
Cut command is used for cut words from file.
Cp command is used for copy files or directory.
- Cut command to select column of characters: in this command we have to we have to define range for characters which we want to cut from a line. Through this command we can cut first 3 characters of each line from file new.txt.
Code:
$ cut -c1-3 new.txt
Let
Cut
Cp
- Cut command to select column of characters : this command used to select particular column from a file. Command can display only second character of each line.
Code:
$ cut -c2 new.txt
e
u
p
- Cut column of characters by using start or end position : in this command we have to specify the start or end position to cut the desired characters. This command extracts 3rd characters of each line from the file. we have specify the start position
Code:
$ cut -c3- new.txt
s creating a file and used this content in it.
command is used for cut words from file.
command is used for copy files or directory.
Code:
$ cut -c-8 new.txt
Lets crea
Cut comma
Cp comman
- Command to select a desired field from line: This command is used to extract whole field and for that you have to specify –f and –d in command with colon.
Code:
$ cut -d':' -f1 new.txt.
Lets
Cut
cp