Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 5802  / 3 Years ago, thu, october 14, 2021, 3:03:48

I have two text files A.txt and B.txt. Each line of A.txt A.txt



100
222
398


B.txt



1  2  103  2 
4 5 1026 74
7 8 209 55
10 11 122 78


What I am looking for is an awk command for doing this:



for each line of A 
search B;
if (the value of third column in a line of B - the value of the variable in A > 10)
print that line of B;

More From » bash

 Answers
5

The following script should solve your problem:



#!/bin/bash
A="$HOME/a.txt"
B="$HOME/b.txt"

cat $A | while read a; do
cat $B | while read b; do
b3=$(echo $b | awk ' { print $3 }')
c=$(($b3 - $a))
if (( $c > 10 )); then
echo $b
fi
done
done


Don't forget to make it executable using the following command:



chmod +x script_name

[#28704] Friday, October 15, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
guialk

Total Points: 300
Total Questions: 144
Total Answers: 121

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;