0

My system generates a flat file with 7 arguments :

Field1,Field2,Field3,Field4,Field5,Field6,Field7
Field1,Field2,Field3,Field4,Field5,Field6,Field7
Field1,Field2,Field3,Field4,Field5,Field6,Field7
Field1,Field2,Field3,Field4,Field5,Field6,Field7
Field1,Field2,Field3,Field4,Field5,Field6,Field7

Each of these fields is an argument to a script. I wish to run the script iteratively (for each line of my file).

This is what I am doing, but it skips the first line of my file.

e.g.

name of my file = v_jay
location = /vjay/project
location of script = /script/vjayscript.ksh

cat /vjay/project/v_jay | while read in; do
  while IFS=, read aa bb cc dd ee ff gg ; do
    /script/vjayscript.ksh $aa $bb $cc $dd $ee $$ff $gg;
  done
done
2
  • it skips the first line because of the while read in - what purpose is that supposed to serve? you're not using $in anywhere else in the script that you've shown.
    – cas
    Feb 17, 2016 at 9:43
  • Hi Jeff. Followup question. one of the script argument can have space in it. e.g. $dd = xyz corporation. Since the script's (vjayscript.ksh) arguments are separated by 'space', the number of arguments now become 1 more than what the script needs and it omits that record. any suggestions?
    – v_jay
    Mar 4, 2016 at 21:13

1 Answer 1

0

Try this (i.e. get rid of the seemingly pointless while read in):

cat /vjay/project/v_jay |
  while IFS=, read aa bb cc dd ee ff gg ; do
      /script/vjayscript.ksh "$aa" "$bb" "$cc" "$dd" "$ee" "$ff" "$gg"
  done
3
  • Hi cas. Followup question. one of the script argument can have space in it. e.g. $dd = xyz corporation. Since the script's (vjayscript.ksh) arguments are separated by 'space', the number of arguments now become 1 more than what the script needs and it omits that record. any suggestions?
    – v_jay
    Mar 4, 2016 at 21:16
  • it's always a problem when the separator character can appear in the data itself. the best solution is to avoid that if at all possible. can you change the input format so that the fields are separated by tabs or commas or something not likely to be in the fields?
    – cas
    Mar 4, 2016 at 23:16
  • sorry, i misunderstood this later problem. that's easily solved - just use double-quotes around all the variables on the command line (i should have done this when i first answered - i usually do, because properly quoting variables is important). i'll edit my answer.
    – cas
    Mar 7, 2016 at 23:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .