Removing a column using AWK

I am trying to extract a column using AWK. The source file is a .CSV file, and below is the command I use:

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

The data in the abc.csv file is shown below:

xyz@yahoo.com,160,1,2,3
abc@ymail.com,1,2,3,160

But the data obtained in test1 is similar to:

abc@ymail.comxyz@ymail.com

when the file opens in notepad after downloading the file from the server.

+4
source share
2 answers

Notepad does not display newlines created on unix. If you want to add them, try

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

Since you are using the Window tool to read output, you just need to tell awk to use Windows line endings as a separator for the output record:

awk -v ORS='\r\n' -F',' '{print $1}' file
+1
source

All Articles