Skip to content
Advertisement

Ubuntu bash script grepping and cutting on first column

I am trying to implement a bash script that will take the piped input and cut the first column and return a total. The difference is that the cut is not from a file, but from the piped input. For example:

JavaScript

Basically, in my scenario the first column will always be from the passed input.

Example usuage is:

JavaScript

data.txt contains:

JavaScript

This will produce something like:

2

How can this be achieved? I have noticed the cut only works for files only. I cannot see any examples on Google.

Advertisement

Answer

I have managed to fix the issue myself. The code is:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement