Ethen Hunt
Ethen Hunt

Reputation: 579

awk and CSV returning only one result

Hi folks trying a very simple awk script to parse a simple CSV. The script runs, however I am getting only one result instead of two.

CSV file:

Test4|Test5|Test6
Test1|Test2|Test3

Script:

#!/bin/bash
awk -F "|" 'NR > 0 {print $2}' UserAgents.csv

Actual Output:

Test5

Expected Output:

Test5
Test2

Upvotes: 1

Views: 122

Answers (2)

Zombo
Zombo

Reputation: 1

It looks like you are on a Mac, with CR line endings, this can be workaround:

awk '{print $2}' FS='|' RS='\r'

Result:

Test5
Test2

Upvotes: 3

Ethen Hunt
Ethen Hunt

Reputation: 579

Changing the file encoding to Unix (LF) resolved the issue.

Upvotes: 0

Related Questions