Problem with reading a specific column in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with reading a specific column in unix
# 1  
Old 08-14-2009
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.
# 2  
Old 08-14-2009
Quote:
Originally Posted by sailaja_80
...

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}')
Let's say your delimited data file is as shown below:

Code:
$ 
$ (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:

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

Quote:
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.

...
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
# 3  
Old 08-14-2009
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.
# 4  
Old 08-14-2009
Quote:
Originally Posted by sailaja_80
...
I want to read record line by line.
and i want only one value at a time
...
(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
# 5  
Old 08-15-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies

2. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. Shell Programming and Scripting

Problem to print out record got smallest number in specific column

Hi, Anybody know how to print out the record that shown smallest number among column 3 and column 4 Case 1 Input : 37170 37196 77 51 37174 37195 73 52 37174 37194 73 53 Case 1 Output : 37170 37196 77 51 Case 2 Input : 469613 469660 73 ... (4 Replies)
Discussion started by: cpp_beginner
4 Replies

5. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

6. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

7. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

8. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

9. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

10. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies
Login or Register to Ask a Question