Skip to main content
Update to handle CSV.
Source Link
icarus
  • 19.1k
  • 1
  • 42
  • 57

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c+0}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5'

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

Edit: The file originally appeared to be a tab separated file, now it has been edited to be a CSV. This means the solutions need to be

awk -F, 'length($1)>3 {c++} END {print c+0}'
awk -F, 'length($1)==5'
awk -F, 'length($1)==5 && $1 !~ /[^0-9]/'

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c+0}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5'

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c+0}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5'

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

Edit: The file originally appeared to be a tab separated file, now it has been edited to be a CSV. This means the solutions need to be

awk -F, 'length($1)>3 {c++} END {print c+0}'
awk -F, 'length($1)==5'
awk -F, 'length($1)==5 && $1 !~ /[^0-9]/'
+0 to print 0 if variable c was not set; typo fix
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 117

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print cc+0}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5`==5'

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5`

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c+0}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5'

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.

Source Link
icarus
  • 19.1k
  • 1
  • 42
  • 57

This seems like homework!

Count lines where length of column 1 is greater than 3

awk 'length($1)>3 {c++} END {print c}'

Discard lines where length of column 1 is not 5

awk 'length($1)==5`

Discard lines where length of column 1 is not 5 and it contains a non digit

awk 'length($1)==5 && $1 !~ /[^0-9]/'

Use the shell to direct the output to the new file.