Use grep to write gpspipe data

198 views Asked by At

I am trying to use the gpspipe tool to create a file output of latitude and longitude data from a usb receiver I have plugged in. All I am interested in is the latitude and longitude (and potentially speed), so I have constructed the current line of code isolating the GPPA lines (which have this info).

gpspipe -r -t -o test.txt | grep GPPA

However this just writes all the NMEA data directly to the file skipping the grep command, I assume this is as the -o is presented first, however neither of the following lines work either.

gpspipe -r -t | grep GPPA | gpspipe -o test.txt
gpspipe -r -t | grep GPPA | > test.txt

The former fails to run and the latter writes a blank file, this is the first real project I am undertaking using linux so am a little unsure on command construction, is it possible to get the output I want i.e. a line by line .txt file of only the GPPA lines?

1

There are 1 answers

9
Dominique On

You almost got the solution:

gpspipe -r -t | grep "GPPA" > test.txt

Obviously, this only works when this command gives you the results you're looking for:

gpspipe -r -t | grep "GPPA"

If not, just launch gpspipe -r -t and check for the presence of GPPA in the results. When you're dealing with capitals and small letters, you might use grep -i "GPPA" for working in a case insensitive way.

In case you have issues with file permissions, you might make sure the file exists and then launch the following command:

gpspipe -r -t 2>&1 | grep "GPPA" >> test.txt
  1. The 2>&1 makes sure that ALL output (normal output and error output) is redirected to the output file.
  2. The >> adds the information to the already existing file.