Problem with reading a specific column in unix

Hi

I have 3 problems.

1)I have to read the 16th column of a record in a comma seperated text file in a shell script . i am trying to use ...

va =( echo $line | awk -F'[.|,]' '{print $16}')

2) I need to create a log and error record for each of the sql commands executed in unix.

3) and i need a unix command to connect to perforce ( version control ssystem) in a shell script and fetch a file from there.

Please help and let me know how can i achieve this.

Let's say your delimited data file is as shown below:

$ 
$ (seq -s, 1 20; seq -s, 11 30; seq -s, 21 40) >data.txt
$ 
$ cat data.txt
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
$ 

Then your awk script could be:

$
$ awk -F, '{print $16}' data.txt
16
26
36
$ 

For (2), show an example of what exactly you want. Show your script, your input and the expected output.

For (3), no idea what perforce is or how to connect to it, sorry. You may want to read the documentation that came with that tool.

tyler_durden

Thanks much for your reply.

I want to read these values in a while loop meaning
I want to read record line by line.
and i want only one value at a time, instead of getting all the values at a time. can you pls help.

(1) Why line by line ?
(2) What do you intend to do with each value per iteration ?
(3) What exactly are you trying to do ?

tyler_durden

My requirement is like this.
I have a text file having comma seperated values of these records .
OName OType SrcDB Sschema targetdb TSchema Load Dataype processY/N
aa Table a e i m Y db2 y
aa index b c d e N sql N

Now i have to open read the file record wise,

check if last column processy/n is yes,
then check the datatype
if it is db2
then connect to db2
check the otype column value
based on type of object i have to execute the below operations.

so my shell script should have all the possible commands present. my script should check type of the object, replace varaiables with values picked from record and execute the shell script.

ex create <SrcDB> <targetdb> <Sschema> <TSchema> <OName>

and then send the output to log and error files.

I am new to unix and not able to proceed any where.
Please help me.

Thanks much for your help.

---------- Post updated at 08:16 PM ---------- Previous update was at 08:06 PM ----------

Thanks so much durden for your help.

Can you please let me know if you need some more details.

Thanks again

---------- Post updated at 10:15 PM ---------- Previous update was at 07:16 PM ----------

hi,

Can some one help me how to retrieve column values row by row

My requirement is like below :

I have a text file having comma seperated values of these records .
OName OType SrcDB Sschema targetdb TSchema Load Dataype processY/N
aa Table a e i m Y db2 y
aa index b c d e N sql N

Now i have to open read the file record wise,

check if last column processy/n is yes,
then check the datatype

basically i want to get a nth column values one after another not as a single result.

Some one help me pls it would be of great help
thanks much