Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a text file based on delimiter using linux command line

Tags:

awk

I have a file with the following lines of text:

jeremy , thomas , 123 
peter , paul , 456 
jack , jill , 789

I would like to remove all of the data except for the center item. For example ending up with a file which contains:

thomas
paul
jill

I have tried so many awk patterns my brain is exploding. Any help would be appreciated.

like image 809
user1488639 Avatar asked Jan 14 '23 20:01

user1488639


2 Answers

Try awk:

awk -F '[[:space:]]*,[[:space:]]*' '{print $2}' input.txt
like image 157
kev Avatar answered May 22 '23 18:05

kev


Try this

cat <filepath> | tr -d ' ' | cut -d',' -f2
like image 20
Necrolyte2 Avatar answered May 22 '23 18:05

Necrolyte2