Unix S39 : cut command and various options with clear examples
Session-39. cut command and various options with clear examples
cut command and various options with clear examples
1)Display character on the specific position in every record ?
cut -c 9 test.txt
-c means specific character
2)Display range of characters in every record
cut -c 5-10 test.txt
It will display 5th to 1oth character in every record
cut -c 5- test.txt ⇒ it will display 5th to last records
cut -c -3 test.txt ⇒ it will display 1st to 3 rd characters in in every record
cut -c 1-3,5-7 ⇒ it will display 1st to 3rd and 5th to 7th characters in every row
Display specific column data :
cut -d "," -f 2 test.txt
-d means delimiter (separator) -default is tab
-f means field
Range of columns
cut -d "," -f 1-3 test.txt cut -d "," -f 1- test.txt cut -d "," -f 2- test.txt cut -d "," -f 1,3 test.txt ==>only 1st and 3rd columns will get
Skip specific column :
Display all columns except specific column
cut -d "," --complement -f 2 test.txt ⇒ it will display all column except 2nd columns cut -d "," --complement -f 3- test.tx ⇒ it will display first two columns cut -d "," --complement -f -3 test.tx==>excpet 1-5 remaining all
Ok first off I want to say this looks like it could potentially be an extremely handy and helpful tutorial. There is just two things hindering it though: context and markdown.
When you begin this tutorial you provide a healthy indication of what the cut command is and how it works, but we don’t know a few extremely important things about it. For example, what language is it used in? Is it a shell command? And sql function? Part of a java library? And in addition to( and because of) this we have bod idea what kind of data it actually is working with. Is it a text file? A database? A program?
Finally, the formatting isn’t very explicit, and it’s difficult to understand where the commands begin and the explanations end. For this I suggest code blocks for your examples and headers for your, well, headers.
## This Is A Header
This Is A Header
code block example:
# this is some python code.
for i in range(0,100):
# this is some python code. def print100(line): for i in range(0,100): print(line)