Hola! I put together a mini Linux text-filter examples using a data.csv file. I have copy/paste it below for your reference.
I’m going to use commands like cut, grep, awk, sort, uniq, head, tail, and wc.
I’ll explain each example and you can run them on your Linux command line. But first, I needed to grab a good beer and get inspired.

data.csv sample file: (you can copy/paste it into your terminal)

Name,Age,Department,Salary
Alice,30,HR,45000
Bob,25,IT,50000
Charlie,35,Finance,55000
Diana,28,Marketing,47000
Ethan,40,IT,60000
Fiona,32,Finance,53000
George,29,HR,46000
Hannah,31,Marketing,48000

Show only the names from the CSV

cut -d',' -f1 data.csv

-d',' → delimiter is a comma.
-f1 → first field only.

Show only employees in the IT department

grep ",IT," data.csv

Searches for lines containing ,IT, to avoid partial matches.

Show employees earning more than 50,000

awk -F',' '$4 > 50000' data.csv

-F',' → set field separator to comma.
$4 > 50000 → filter where Salary (field 4) is greater than 50,000.

Sort employees by Salary (highest first)

sort -t',' -k4 -nr data.csv

-t',' → delimiter comma.
-k4 → sort by 4th column (Salary).
-n → numeric sort.
-r → reverse order.

Count how many employees are in each department

cut -d',' -f3 data.csv | sort | uniq -c

First cuts the Department column.
Sorts it.
uniq -c → shows counts.

Show only the first 3 employees in the file

head -n 3 data.csv

Show the last 2 employees in the file

tail -n 2 data.csv

Find all employees with names starting with “A”

grep "^A" data.csv

^A → regex meaning “starts with A”.

Add $1000 to each employee’s salary (display only)

awk -F',' '{if(NR==1){print $0} else {$4=$4+1000; OFS=","; print}}' data.csv

Leaves the header row intact (NR==1).
Adds 1000 to field 4 for all other rows.

Count total employees in the file (excluding header)

tail -n +2 data.csv | wc -l

tail -n +2 → skip header.
wc -l → line count.

I hope these Linux text-filter examples are useful for you. If you like to support me please consider buying one of my T-Shirt or coffee mugs designs in my shop. Thanks!

Leave a comment

Your email address will not be published. Required fields are marked *