1

I have the following problem: Script

#!/usr/bin/ksh

for unitcaseno in `cat /pims/nigel/UNLOAD-DB/xaa`
do
        echo "String = $unitcaseno"
        unitno=`echo $unitcaseno | cut -d'|' -f1`
        caseno=`echo $unitcaseno | cut -d'|' -f2`
        echo "Unitno = $unitno:Caseno = $caseno"
break
done

The file is very large so I am breaking after the first record.

Sample file:
  349702|            1|
  349702|            1|
  349702|            1|
 1133247|            6|
 1133247|            6|
 12708  |            1|
 12708  |            1|
 299466 |            2|
 299466 |            2|
 299466 |            2|
 299466 |            2|
 501877 |            1|
 501877 |            1|
 55871  |            9|
 55871  |            9|
 64239  |            7|
 64239  |            7|

Output

String = 349702|
Unitno = 349702:Caseno =

My problem is that it is not printing out the second field in either output.

4

The problem you're having is with the

for unitcaseno in `cat /pims/nigel/UNLOAD-DB/xaa`

structure. This will split the file into words, not lines. This is why you see String = 349702 in the output; you're only seeing the first word and not the whole line.

Instead consider a loop similar to

while read unitcaseno
do
  ....
done < /pims/nigel/UNLOAD-DB/xaa

Now you're processing a line at a time

String = 349702|            1|
Unitno = 349702:Caseno =  1

Note you have other problems; eg extra whitespace before the Caseno. But this should get you to the next step!

  • Hi Stephen, Thanks for that it solves my problem and the white space I can handle – Nigel B Jul 21 '16 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.