Skip to content
Advertisement

Swap two columns depending on condition for third column in linux

I have a file with 3 columns like this

JavaScript

I want to swap the entries of the Col1 and Col2 whenever there is

JavaScript

in the third column. I want my output file to be like

JavaScript

Advertisement

Answer

JavaScript

Essentially, if $3=="<-", then swap the columns and redefine $3. Then print.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement