AWK Script

Zedicus

New Member
Joined
Jan 14, 2021
Messages
2
Reaction score
0
Credits
26
Hello,
I'm new to AWK scripting. Sorry for my English.
I'm trying to filter based on column number. There is something which intrigues me. If I do $7 in order to filter based on the column 7, the color of $7 is red. But if I do $26, only the $2 is red and the 6 is black. It's the same for all the numbers greater than nine.
I wonder if I should filter by using $26. Is it correct? Why the second number is not coloured?
Thanks.
 

Attachments

  • Capture d’écran, le 2021-04-20 à 12.00.22.png
    Capture d’écran, le 2021-04-20 à 12.00.22.png
    35.9 KB · Views: 206


I don't know much about awk but I think it may have to do with missing a closing '
Your code
Code:
awk -F "\t" '{
    if(($26 <= 1)) {
       print $Line
   }
I think it should probably be.
Code:
awk -F "\t" '{
    if(($26 <= 1)) {
       print $Line
   }'
And if not maybe this?
Code:
awk -F "\t" '{
    if(($26 <= 1)) 
       print $Line
   }'
Or try looking in that direction because where you open you also need to close.
 
Please, for the love of all that's holy, do not use pictures of text.

It's text. This is a forum. It's meant for text. Text also makes it easier for us to help you. Use the code tags or spoiler tags if it's a lot (or a paste service).
 
I don't know much about awk but I think it may have to do with missing a closing '
Your code
Code:
awk -F "\t" '{
    if(($26 <= 1)) {
       print $Line
   }
I think it should probably be.
Code:
awk -F "\t" '{
    if(($26 <= 1)) {
       print $Line
   }'
And if not maybe this?
Code:
awk -F "\t" '{
    if(($26 <= 1))
       print $Line
   }'
Or try looking in that direction because where you open you also need to close.

You're right, the code hasn't been closed off properly with a single quote '.
$26 is NOT the problem.

@Zedicus - From looking at the image you posted, you are using awk to process a tab delimited file, is this correct?
And from the code in the image, it looks to me like you are using awk to process each line in the file. And if the field/column at position $26 is less than or equal to 1, you want to output the entire line.

If that's the case, I would do something like this:
Bash:
awk -F "\t" '{ if ($26 <= 1){print}}' /path/to/input-file
Or if you're using input redirection:
Bash:
awk -F "\t" '{ if ($26 <= 1){print}}' < /path/to/input-file

Note:
In the example in your image, the variable $Line is not defined, or declared anywhere.
So the print statement in your if will just print the entire line anyway.
But $Line doesn't do anything as far as I can see, it's just an empty/non existent variable.
You could replace $Line with $0 - which in awk, represents the entire line that was read from the file.

But if you just call print on it's own, it will print the entire line anyway!
So in order to output the entire line, you'd simply call print.

I hope this helps!
 

Members online


Top