Score:-1

AWK Simple way on my way- Need assistance in bash

kr flag

I have below data in a file and need output like this - I did in very bad/hard way looking for something smart way.

file1.log:

A  B  C
1  4  6
2  4  4

We should compare col A values i.e is 1 = 2 if so matched else not-matched.

a1=$(awk -F "|" '{print $3}' file1.log|xargs|awk '{print $1}')
a2=$(awk -F "|" '{print $3}' file1.log|xargs|awk '{print $2}')
if [[ "$a1" == "$a2" ]]; then
     echo "MATCHED"
else
     echo "NOT-MATCHED"
fi
bac0n avatar
cn flag
It's not clear what you are trying to accomplish.
HuHa avatar
es flag
You don't describe what your _input_ file (files?) looks like. You don't describe the task. And this looks awfully like a homework assignment.
Cyrus avatar
cn flag
Please add your desired output (no description, no images, no links) for that sample input to your question (no comment).
Score:0
cn flag

Try this command:

awk 'BEGIN {p=""} {if(p==$1) {print "matched"; p=$1} else {print "not matched"; p=$1}}'
 file1.log

You get:

not matched
not matched
not matched

To skip the first line:

awk 'BEGIN {p=""} NR>1{if(p==$1) {print "matched"; p=$1} else {print "not matched"; p=$1}
}' file1.log 

not matched
not matched

You may need to use NR>2 in the above statement. It all depends on what you are trying to do -- your question is not clear as it is.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.