i have a file which has few columns.From those columns i need to check the value of column 9 if it is 1 or not.If it is 1 then only i need to print column 4,5,7,9.
In the above input heading 1,heading 2 and heading 3 are various headings in the file.
Also first column header start from line 3 in the file.
hi..Thanks for the reply.
but input value can be anything..There are more than 1000 records in the file in a similar pattern.There should be some loop etc.
I dont want to hardcode the input values.
The input file has 1000 records of similar pattern as the sample input file that I have given.
However in the script you are hard coding the input values as below
print $4,$5,$7,$9}' OFS=, input
value 4h,value 5h,Value 7h,1
value 4c,value 5c,Value 7c,1
I think there should be some loop which take the values from input .csv file and then redirect the output based on search critaria(where column 9 has value 1) to some output file.
The input file has 1000 records of similar pattern as the sample input file that I have given.
However in the script you are hard coding the input values as below
print $4,$5,$7,$9}' OFS=, input
value 4h,value 5h,Value 7h,1
value 4c,value 5c,Value 7c,1
I think there should be some loop which take the values from input .csv file and then redirect the output based on search critaria(where column 9 has value 1) to some output file.
No! The script neutronscott gave you was:
which specifies that the input field separator is comma (-F,), the output field separator is comma (OFS=,), and for every line in your input file (you didn't say what the name was, but this code assumes that the input file is named input) if the ninth field is 1 ($9==1) it will print the 4th, 5th, 7th, and 9th fields (print $4,$5,$7,$9). Then he showed that with the input you supplied, it produces the output:
which is exactly what you asked for. If you have a different name for your input file change input in the script to the name of your input file. If you want to save the output in a file, add
to the end of the awk command.
This command wil work just fine with zero lines of input or as many input lines as are present in any csv file you give it (as long as you have space to store the output in the file to which you redirect output and input lines are no longer than LINE_MAX bytes for whatever value LINE_MAX is on your system).
hi
I have 2 file with more than 10 columns for both
1st file
apple,0,0,0......
orange,1,2,3.....
mango,2,4,5.....
2nd file
apple,2,3,4,5,6,7...
orange,2,3,4,5,6,8...
watermerlon,2,3,4,5,6,abc...
mango,5,6,7,4,6,def.... (1 Reply)
Input File:-
COLUMN1 COLUMN2 COLUMN3 COLUMN4 COLUMN5 COLUMN6 SMS Email AO Mail Post N Cell
VEGE Potato E W 396 12 0 384 0 0 0 0 0
VEGE Onion S W 17 0 17 0 0 0 0 0 0
FRUIT APPLE N W 549 61 0 0 0 0 0 488 0
FRUIT APPLE SE W 291 14 239 38 0 10 0 0 0
FRUIT APPLE EAMS W 397 32 309 56 309 309 0... (27 Replies)
Dear Unix experts,
I have got a file where I would like to compare the values of second column if first column is same in such a way that the difference between the values is >50. If not, I would like to discard both values.
For example, my input file looks like -
comp275_c0_seq2 73... (7 Replies)
Hi,
I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file.
File1 - file2 = file3
wc -l file1.txt
58112
wc -l file2.txt
55260
head -5 file1.txt
101214200123
101214700300
101250030067
101214100500... (10 Replies)
Hi,
I know that this topic has been discussed in the past and I've tried to follow all the guidelines. Anyhow, I following describe my problem.
I have a file (file1 , no. records = 67) containing pairs of IP addresses as follows (with single space as delimiter between the fields):
example... (5 Replies)
hi Friends
need to compare columns in one file where the data looks like below
laptop,IBM
phone,samsung
car,rental
user1,laptop
user2,laptop
user3,phone
want to get output as
laptop,IBM
phone,samsung
car,rental
user1,IBM
user2,IBM
user3,samsung
need to seach $2 in array of $1 and... (4 Replies)
Hi,
I am new to unix and I need help in solving below mentioned issue, really appreciate ur help.
I have a file
sam, john, 2324, 07142007
tom, thomson, 2343, 07142007
john, scott, 2478, 07142007
its a comma delimited file, I need to extract the last column from each line and this... (4 Replies)