Abhinav
Abhinav

Reputation: 709

extracting the column using 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.

Upvotes: 5

Views: 2257

Answers (2)

Ed Morton
Ed Morton

Reputation: 204648

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

Upvotes: 1

Jakuje
Jakuje

Reputation: 26016

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

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

Upvotes: 6

Related Questions