Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting the column using AWK

Tags:

linux

awk

I am trying to extract column using AWK. Source file is a .CSV file and below is command I am using:

 awk -F ',' '{print $1}' abc.csv > test1

Data in file abc.csv is like below:

[email protected],160,1,2,3
[email protected],1,2,3,160

But data obtained in test1 is like :

[email protected]@ymail.com

when file is opened in notepad after downloading the file from server.

like image 562
champs Avatar asked Jul 11 '15 21:07

champs


2 Answers

Notepad doesn't show newlines created on unix. If you want to add them, try

awk -F ',' '{print $1"\r"}' abc.csv > test1
like image 169
Jakuje Avatar answered Oct 22 '22 08:10

Jakuje


Since you're using a Window tool to read the output you just need to tell awk to use Windows line-endings as the Output Record Separator:

awk -v ORS='\r\n' -F',' '{print $1}' file
like image 32
Ed Morton Avatar answered Oct 22 '22 10:10

Ed Morton