I have file on below pattern, and i want to write a generic awk to handle all cases.
input_file:
col1~col2~col3~col4~col5~col6
I need to generate 4 files something like this
File1:
col1~~col2~~col3
File2:
col1~~col2~~col4
File3:
col1~~col2~~col5
File4:
col1~~col2~~col6
I have written
I have written above awk under for loop so that this column_no get incremented everytime, so that it picks up different colum for each iteration. [[ and also out_file_name variable get changed in each iteration]]
when i execute this, I get output as
File 1:
col1~~col2~~3 <== prints number "3" instead of picking thrid column value from the input file.
[[ Same thing for all the files ]]
Am i overlooking awk to achieve my request? Pls correct me if doing something wrong or sytax problem.
I knew it can be achieved by writting 4times. But my actual case it is more than 12. So thought of writting professional way, to handle all possible cases.
Kind Regards,
Balaji.
Note I tried another approach also
but hasnt pass syntax validation.
---------- Post updated at 11:06 AM ---------- Previous update was at 10:31 AM ----------
I have acheived through below code.
Let me know if there is further best way to code this.
Hello,
I want to get the maximum value of each record separated by empty line based on the 3rd column of each row within each record?
Input:
A1 chr5D 634 7 82 707
A2 chr5D 637 6 82 713
A3 chr5D 637 5 82 713
A4 chr5D 626 1 82 704... (4 Replies)
Hello,
I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2
SDF4 -0.211654
SDF4 0.978068
... (1 Reply)
Hi, I'm running via PuTTY, in a BASH shell to do my work. I'm running calculations where steps are reported like this every 100 steps:
NSTEP = 249900 TIME(PS) = 249.900 TEMP(K) = 299.94 PRESS = 21.1
Etot = -12912.5557 EKtot = 4996.8780 EPtot = -17909.4336
... (6 Replies)
Hi All,
I have browsed through the forums for a similar topic, but there is no topic which explains about this problem, when the backend is DB2.
I want to assign the output of a select count(*) from tablename to a unix variable in a shell script.
I am using ksh.
The database used to... (3 Replies)
Problem,
How can you pass today's date (eg) 18 into Awk and select the field representing the 18th column?
I have an output that I want to interact with based on what day it is
information=0:0 192:0 5436:0 22:99 0:0 0:0 1234:0 1359:09
DAY=date'+%d'
numbrs=`$information | awk... (2 Replies)
Hi,
I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use..
Please can any body help me in this regards
Thanks & Regards
Abdul Hafeez Shaik (17 Replies)
As part of a bigger task, I had to read thru a file and separate records into various batches based on a field. Specifically, separate records based on the value in the batch field as defined below. The batch field left-justified numbers.
The datafile is here
> cat infile
12345 1 John Smith ... (5 Replies)
The awk command awk -F: '{print $1}' test1 gives the first columns of all the lines in file ,is there some command to get a particular column from particular line .
Any help is appreciated.
thanks arif (4 Replies)