1

My CSV file is like this >>

ABC XYZ 111 FRANCE
GGG KKK 222 France
HHH     666 France
France     886 USA

when I run the command

$ awk -F',' '($4 ~ /FRANCE/) { print $4 }' test.csv 

it shows me FRANCE only

All I want it to read France , FRANCE , FrAnce and france must be in 4th column,

how can I ignore case sensitivity and read 4th for france?

Amit Singh
  • 188
  • 9

1 Answers1

2

Could you please try following.

awk 'tolower($NF)=="france"{print $NF}' Input_file

OR in case you have comma delimited Input_file try:

awk 'BEGIN{FS=","} tolower($NF)=="france"{print $NF}' Input_file

2nd solution: Or with GNU awk use IGNORCASE:

awk 'BEGIN{IGNORECASE=1} $NF=="france"{print $NF}'  Input_file

OR in case you have comma delimited Input_file.

awk 'BEGIN{FS=",";IGNORECASE=1} $NF=="france"{print $NF}'  Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • All 4 solutions you gave provide no results.. awk 'BEGIN{FS=",";IGNORECASE=1} $4=="france"{print $4}' test.csv awk 'BEGIN{IGNORECASE=1} $4=="france"{print $4}' test.csv awk 'BEGIN{FS=","} tolower($4)=="FRANCE"{print $4}' test.csv awk 'BEGIN{FS=","} tolower($4)=="FRA"{print $4}' test.csv and so on.. I actually try a lot with these earlier but got nothing from the internet... The summary is France must be in 4th column ... awk must not read the 1st column. If I write France / FRANCE / france, it must read all frane similar to "grep -i " but in 4th column only... – Amit Singh Nov 15 '19 at 09:30
  • @CorOmnes, Yes it is not reading 1st column. – RavinderSingh13 Nov 15 '19 at 09:32
  • PS: I am using mac terminal – Amit Singh Nov 15 '19 at 09:34
  • @CorOmnes, Is it not giving your correct results? It worked fine for me. – RavinderSingh13 Nov 15 '19 at 09:35
  • I saw 3rd option, it should work for me... pls have a look... >> https://drive.google.com/file/d/1t1CYhbN0ZmCfPgdKIPzj-JDhnlduBV9U/view – Amit Singh Nov 15 '19 at 09:48
  • @CorOmnes, sorry I can't open this link in office system, please type it and let me know then. – RavinderSingh13 Nov 15 '19 at 10:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202396/discussion-between-cor-omnes-and-ravindersingh13). – Amit Singh Nov 15 '19 at 10:56