-2

I am trying to print columns in file which are seperated by | using awk.

File content:

 postgres  | psql                   |               | 2018-09-17 05:00:45.096491+00 |            | active
 test_user | PostgreSQL JDBC Driver | ***.**.**.118 | 2018-09-17 03:55:22.310569+00 |            | idle in transaction
 test_user | PostgreSQL JDBC Driver | ***.**.**.95  | 2018-09-17 03:54:58.638521+00 |            | idle in transaction

I am using below awk command to separate columns in file.

 awk 'BEGIN { RS = "|" } ; { print $2 }' vv.txt

Also refer to image attached which gives clear idea about issue. I am not sure why data is getting messed up? Is it also considering space as separator?

enter image description here

simlev
  • 839
  • 2
  • 11
  • 24
Nomad
  • 939
  • 4
  • 15
  • 28

1 Answers1

0

Problem:

As was explained in the comments, you modified the record separator instead of the field separator.

Solution:

awk -F'|' '{ print $2 }' vv.txt

Output:

psql
PostgreSQL JDBC Driver
PostgreSQL JDBC Driver
simlev
  • 839
  • 2
  • 11
  • 24