how to iterate line by line from csv file and use awk command to separate the comma , field

i want to loop in file to read line by line and in same line seperate the comma, with awk for example

i have file called gpc.csv which contain comma separated value , I want to read leach line and separate feild 3 and 4

gpc.csv file

i want to loop in file to read line by line and in same line seperate the
comma, with awk for example

i have file called gpc.csv which contain comma separated value , I want to
read leach line and separate feild 3 and 4

I'm not sure if I understand you correctly, but you are trying to print out column 3 and 4?

gpc.csv file
###########
Production,Run PoverA script for
Owner,pbst_o1,/appl/pbst/pbst_o1/bin/povera_bst.ksh,20
Production,Run PoverA script for
Batch,pbst_b1,/appl/pbst/pbst_o1/bin/povera_bst.ksh,30
Acceptance,Backup .passfile file,abst_o,cp
/appl/abst/abst_o1/etc/bst/.passfile /tmp,5
Acceptance,Clearing BATCH files from var/log and var/tmp folder, abst_b,
"rm -rf /appl/abst/abst_o1/var/log/* /appl/abst/abst_o1/var/tmp/*;\
find /appl/abst/abst_o1/var/log/ -user abst_b1 -type f -exec rm {} ;\
find /appl/abst/abst_o1/var/log/ -user abst_b1 -type l -exec rm {} ;\
find /appl/abst/abst_o1/var/tmp/ -user abst_b1 -type f -exec rm {} ;\
find /appl/abst/abst_o1/var/tmp/ -user abst_b1 -type l -exec rm {} ;\
find /appl/abst/abst_o1/var/log/ ! -name log -user abst_b1 -type d -exec
rmdir {} ;\
find /appl/abst/abst_o1/var/tmp/ ! -name tmp -user abst_b1 -type d -exec
rmdir {} \,5"
Acceptance,Clearing OWNER files from var/log and var/tmp
folder,abst_o,"find /appl/abst/abst_o1/var/log/ -user abst_o1 -t\ype f
-exec rm {} \;\
find /appl/abst/abst_o1/var/tmp/ -user abst_o1 -type f -exec rm {} \;
find /appl/abst/abst_o1/var/log/ ! -name log -user abst_o1 -type d -exec
rmdir {} \;
find /appl/abst/abst_o1/var/tmp/ ! -name tmp -user abst_o1 -type d -exec
rmdir {} \;
ls -1a /appl/abst/abst_o1| grep -Evw "".|..|var|.ssh"" | xargs -I {} rm -rf
{},5"
Acceptance,Creating tmp folder,abst_o mkdir -m 2775 /appl/abst/abst_o1/tmp,5

playbook i am using but it is not working as i want:
###########################################

---
- hosts: localhost
  connection: local

  tasks:

   - name: display multiple file contents
     shell: echo item
     with_file:
           - gpc.csv
     register: command

   - debug: "var={{item}} | awk -F [,] '{ print $3 }'"
     with_items: command

You can't use awk in Ansible. That is a shell command and can only be used in modules shell and command.

But you could do something like this.

   - debug: msg="'{{ item.split(',')[2] }}' '{{ item.split(',')[3] }}'"
     with_lines: cat gpc.csv

Yes you understood correctly I want to run loop over gpc.csv file and print 3 and 4 ,

i tried but spiting with index number is not working , Following error is throwing

Following playbook using as suggested:

tasks:

  • name: Iterating line by line and priniting cooum 3 & 4
    debug: msg=" ‘{{ item.split(’,‘)[3] }}’ ‘{{ item.split(’,‘)[4] }}’ "
    with_lines: cat gpc.csv

error: