Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.
Extract Text
cut
is a good cool to extract text that follows some schema such as tab or comma delimited.
Create A File With Comma Separated Text
echo "chris, 34, male" >> staff.txt
echo "sarah, 22, female" >> staff.txt
echo "Bob, 59, male" >> staff.txt
View File
cat staff.txt
chris, 34, male
sarah, 22, female
Bob, 59, male
Extract Text By Breaking Into Columns
cut
the text in staff.txt
that is separated by commas (-d ','
) into columns, then take the second (-f 2
) column.
cut -d ',' -f 2 staff.txt
34
22
59
## Extract Certain Chunk Of Characters From Each Row
cut
the text in staff.txt
up such that we return the second to the fifth (-c 2-5
) characters of each line.
cut -c 2-5 staff.txt
hris
arah
ob,