Add Columns To Text

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 And Save To File

cut the text in staff.txt that is separated by commas (-d ',') into columns, then take the second (-f 2) column, and finally save to ages.txt

cut -d ',' -f 2 staff.txt > ages.txt

View ages.txt

cat ages.txt

Add ages.txt As New Column Of staff.txt

Add (paste) the content of ages.txt as a new column of staff.txt delimited with a comma (-d ',').

paste -d ',' ages.txt staff.txt
 34,chris, 34, male
 22,sarah, 22, female
 59,Bob, 59, male