Basic Shell Commands

Go to Problems

Cut command in Unix with example

Cut is used to select sections of text from each line of files.

Input:

System ID,School,Phone,Address,City,State,Zip,Type,Principal
569,Happy Valley Elementary School,814-555-1212,332 Innovation Boulevard,State College,PA,16801,Elementary,Mr. Jenkins
570,Happy Valley High School,814-555-1212,328 Innovation Boulevard,State College,PA,16801,High School,Mr. Eric Sparks
571,Happy Valley Middle School,814-555-1212,330 Innovation Boulevard,State College,PA,16801,Middle School,Mrs. Spegle
572,Happy Valley School District,814-555-1212,334 Innovation Boulevard,State College,PA,16801,District Building,Mr. Jones
Get 1 to 5 columns
cat data.csv | cut -c 1-5

Output:

Syste
569,H
570,H
571,H
572,H
Set delimiter and get the first field
cat data.csv | cut -d ',' -f 1

Output:

System ID
569
570
571
572

Serious about Learning Scripting ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum.
Shell scripting
Problem Score Companies Time Status
Valid phone number 150
22:20
Lines in a given range 200
27:57
Remove Punctuations 250
12:54
Transform CSV 300
19:04