Linux ‘Cut’ command is text processing command.we get portion of text from file.It will cut of portion of text from a file.All we need to do is mention the column to cut by specifying the delimiter.
It is not only used to cut data from text files and also can use on csv files.
Let’s go by the usage’s of the linux cut command examples.
Let’s print one file content.
[ SLTMachine:] # cat File.txt
i love simplylearntopics.com
Great content on the simplylearntopics.com
follow facebook page,goolge+ for simplylearntopics.com
Usage 1: How to get first character from “File.txt”
[ SLTMachine: ] # cut -c 1 File.txt i G f
It will print the first character using “-c” option.
Usage 2: How to get first character and 3d character from “File.txt”
SLTMachine: # cut -c 1,3 File.txt il Ge fl
Usage 3: How to get first word from every line from “File.txt”
[ SLTMachine: ] # cut -f 1 -d ' ' File.txt i Great follow Usage
Here “-d” means delimiter,we are giving single space as dimilter
Usage 4: How to get first word and third word from every line from “File.txt”
[ SLTMachine ~] # cut -f 1,3 -d ' ' File.txt i simplylearntopics.com Great on follow page,goolge+ Usage Lets'
Usage 5: How to get first word and third word from every line from “File.txt” which has dilimiter “,”
[ SLTMachine ~] # cut -f 1,3 -d ', ' File.txt
Usage 6: How to get every line by skipping first 3 letters from every line
[SLTMachine ~]# cut -c 3- File.txt love simplylearntopics.com eat content on the simplylearntopics.com llow facebook page,goolge+ for simplylearntopics.com
Usage 7:How to get first 3 letters from every line from “File.txt”
[SLTMachine ~]# cut -c 1-3 File.txt i l Gre fol
Usage 8:How to avoid printing first field and print rest of the each line.
[SLTMachine ~]# cut -f 1 --complement -s -d ' ' File.txt love simplylearntopics.com content on the simplylearntopics.com facebook page,goolge+ for simplylearntopics.com
I am printing each line except first word and considering ” ” space as one delimiter.
Usage 9:How to replace specific character with another character.
echo 'simply;LearnTopics' | cut -d ';' -f 1,2 --output-delimiter=' '
Usage 10:How to print up to 5th Character in given line
echo 'simplyLearnTopics' |cut -c -11 simplylearn
Usage 11: Print from 5th character to the end of the line.
echo 'simplyLearnTopics' |cut -c 10 -
Usage 12:How to display first field from the /etc/passwd file?
[SLTMachine ~]# cut -d':' -f1 /etc/passwd
Usage 13: Print specific column by using specifying the Byte option.
[SLTMachine ~]# cut -b 2 File.txt
Print second character from File.text in every line.The output is equal to output if we use the below option
( or )
[SLTMachine ~]# cut -c 2 File.txt
Usage 14: Get List of File names in the current directory
[SLTMachine ~]# ls -al | cut -c44-
Usage 15: If you want more options and help on the cut command options,use the following option.
[SLTMachine ~]# man cut (or) [SLTMachine ~]# cut --help
Thanks for Reading the 15 Linux Cut Command Examples.If you have any new usage of cut command,please post it in the comment section.I will add it in this post.
Happy Simply Learners 🙂
Latest posts by SRINIVAS DARIPELLI (see all)
- delete complete linked list with program and Images,better understanding - February 24, 2017
- How to Rotate Linked List with Easy 4 Steps,explained with images - February 21, 2017
- Delete loop from linked list,made easy with 9 Pictures - February 17, 2017