2013-05-29 67 views
0

我在我的Bash腳本中遇到了一個問題,當我想使用我的腳本時,它在第8行和第43行顯示「模糊重定向」。我讓腳本處理GPS數據。在Linux中不明確的重定向

我的腳本如下:

#! /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 

當我運行此我得到:

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

該行及其有關:

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

這是什麼,以及如何解決這個?

回答

1

heredoc中使用awk腳本。

#! /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 
+0

謝謝!爲了解決我的腳本和Heredoc的信息! – Firy

+0

另請參閱http://stackoverflow.com/faq#howtoask – devnull