Firy
Firy

Reputation: 1

Ambiguous Redirect in Linux

I got a problem in my Bash script, when I want to use my script it says "ambiguous redirect" at line 8 and line 43. I made my scripted to process GPS data.

My script is as follows:

#! /bin/bash

# Change 'Raw' to 'csv' for output file name
outf=${1/Raw/csv}

# Print current input- and output file name
echo  \> $outf

# Remove 'Carriage Returns' and get GGA and VTG strings from file
tr -d '\r' < | egrep "GGA|VTG" | awk '
BEGIN {
# Field separator is ','
FS="," 
}

# Convert deg min sec to decimal degrees
function degAngl(minAngl) {
pos = index(minAngl, ".") - 3
deg = substr(minAngl, 1, pos)
min = substr(minAngl, pos + 1) / 60
return deg + min
}

{
# if it is a VTG dump all stored data
if (substr() == "VTG") {
    head=$2
    velo=$8
    printf ("%08.1f,%1.8f,%1.8f,%1.3f,%d,%d,%1.1f,%1.1f,%1.1f\n", time, long, lati, alti, qual, nsat, hdop, head, velo)
}

# it is not a VTG but a GGA, store data, correct for different altitude definitions
else {
    time = 
    lati = degAngl()
    long = degAngl()
    qual = 
    nsat = 
    hdop = 
    alti = ( < 0) ?  +  : 
}
}
' >$outf

When I run this I get:

process.sh: Line 10: : ambiguous redirect
process.sh: Line 43: 1: ambiguous redirect

The lines its about:

line 10: tr -d '\r' < | egrep "GGA|VTG" | awk '
line 43: ' >$outf

What is this and how to solve this?

Upvotes: 0

Views: 2342

Answers (1)

devnull
devnull

Reputation: 123478

Use the awk script within a heredoc.

#! /bin/bash

# Change 'Raw' to 'csv' for output file name
outf=${1/Raw/csv}

# Print current input- and output file name
echo $1 \> $outf

awk_script=$(cat << 'EOS'
BEGIN {
# Field separator is ','
FS=","
}

# Convert deg min sec to decimal degrees
function degAngl(minAngl) {
pos = index(minAngl, ".") - 3
deg = substr(minAngl, 1, pos)
min = substr(minAngl, pos + 1) / 60
return deg + min
}

{
# if it is a VTG dump all stored data
if (substr($1,4) == "VTG") {
    head=$2
    velo=$8
    printf ("%08.1f,%1.8f,%1.8f,%1.3f,%d,%d,%1.1f,%1.1f,%1.1f\n", time, long, lati, alti, qual, nsat, hdop, head, velo)
}

# it is not a VTG but a GGA, store data, correct for different altitude definitions
else {
    time = $2
    lati = degAngl($3)
    long = degAngl($5)
    qual = $7
    nsat = $8
    hdop = $9
    alti = ($10 < 0) ? $10 + $12 : $10
}
}
EOF
)

# Remove 'Carriage Returns' and get GGA and VTG strings from file
tr -d '\r' <$1 | egrep "GGA|VTG" | awk "${awk_script}" >$outf

Upvotes: 1

Related Questions