Skip to main content
deleted 1 character in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

I have a big csv file, which looks like this:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,25178
1,2,3,4,5,6,27986
1,2,3,4,5,6,-99

I want to select only the lines in which the 7th columns is equal to -99, so my output be:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99

I tried the following:

awk -F, '$7 == -99' input.txt > output.txt
awk -F, '{ if ($7 == -99) print $1,$2,$3,$4,$5,$6,$7) }' input.txt > output.txt

But both of them returned an empty output.txt. Can anyone tell me what I'm doing wrong? Thanks.

I have a big csv file, which looks like this:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,25178
1,2,3,4,5,6,27986
1,2,3,4,5,6,-99

I want to select only the lines in which the 7th columns is equal to -99, so my output be:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99

I tried the following:

awk -F, '$7 == -99' input.txt > output.txt
awk -F, '{ if ($7 == -99) print $1,$2,$3,$4,$5,$6,$7) }' input.txt > output.txt

But both of them returned an empty output.txt. Can anyone tell me what I'm doing wrong? Thanks.

I have a big csv file, which looks like this:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,25178
1,2,3,4,5,6,27986
1,2,3,4,5,6,-99

I want to select only the lines in which the 7th columns is equal to -99, so my output be:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99

I tried the following:

awk -F, '$7 == -99' input.txt > output.txt
awk -F, '{ if ($7 == -99) print $1,$2,$3,$4,$5,$6,$7 }' input.txt > output.txt

But both of them returned an empty output.txt. Can anyone tell me what I'm doing wrong? Thanks.

Source Link

Using AWK to select rows with specific value in specific column

I have a big csv file, which looks like this:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,25178
1,2,3,4,5,6,27986
1,2,3,4,5,6,-99

I want to select only the lines in which the 7th columns is equal to -99, so my output be:

1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99
1,2,3,4,5,6,-99

I tried the following:

awk -F, '$7 == -99' input.txt > output.txt
awk -F, '{ if ($7 == -99) print $1,$2,$3,$4,$5,$6,$7) }' input.txt > output.txt

But both of them returned an empty output.txt. Can anyone tell me what I'm doing wrong? Thanks.