[GRASS-user] g.mlist newline separator request

I've noticed that g.mlist doesn't enter a newline after the last entry in a list, which used to be the case about a month ago:

~/coderepo >g.mlist pattern=Minas_Basin*
Minas_Basin_Jan16_2007_50m
Minas_Basin_Jan16_2007_50m_med3
Minas_Basin_Jan16_2007_50m_med3_shade
Minas_Basin_Jan16_2007_50m_med3_shade_comb
Minas_Basin_Jan16_2007_50m_shade
Minas_Basin_Jan16_2007_50m_shade_comb~/coderepo >

Consequently, any script that tries to get a count from g.mlist by piping to wc will get an incorrect count that will be off by one:

g.mlist pattern=Minas_Basin_Jan16_2007_50m | wc -l
0 (Should be 1)

g.mlist pattern=Minas_Basin* | wc -l
5 (Should be 6)

Would it be possible to get the final newline back? I have scripts that are broken now because a for loop never gets started when a check is done against the number of rasters matched:

MATCHES=`g.mlist pattern=${PATTERN} | wc -l`

# Abort if no matches are found.
if [ "$MATCHES" -eq 0 ] ; then
   echo "$SCRIPT: No rasters matched the search pattern!"
   exit 1
fi

~ Eric.

Hi,

this patch should fix it.

But I am not sure whether to commit it to CVS. Patch seems to be
"ugly" for me, moreover I am not sure why printf fn was used in the
script (?)

Martin

2007/4/12, Patton, Eric <epatton@nrcan.gc.ca>:

I've noticed that g.mlist doesn't enter a newline after the last entry in a list, which used to be the case about a month ago:

~/coderepo >g.mlist pattern=Minas_Basin*
Minas_Basin_Jan16_2007_50m
Minas_Basin_Jan16_2007_50m_med3
Minas_Basin_Jan16_2007_50m_med3_shade
Minas_Basin_Jan16_2007_50m_med3_shade_comb
Minas_Basin_Jan16_2007_50m_shade
Minas_Basin_Jan16_2007_50m_shade_comb~/coderepo >

Consequently, any script that tries to get a count from g.mlist by piping to wc will get an incorrect count that will be off by one:

g.mlist pattern=Minas_Basin_Jan16_2007_50m | wc -l
0 (Should be 1)

g.mlist pattern=Minas_Basin* | wc -l
5 (Should be 6)

Would it be possible to get the final newline back? I have scripts that are broken now because a for loop never gets started when a check is done against the number of rasters matched:

MATCHES=`g.mlist pattern=${PATTERN} | wc -l`

# Abort if no matches are found.
if [ "$MATCHES" -eq 0 ] ; then
        echo "$SCRIPT: No rasters matched the search pattern!"
        exit 1
fi

~ Eric.

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

(attachments)

g.mlist.diff (1.85 KB)

Martin,

Thanks for the patch, it works perfectly. Much appreciated!

~ Eric.

-----Original Message-----
From: Martin Landa [mailto:landa.martin@gmail.com]
Sent: Fri 4/13/2007 5:06 AM
To: Patton, Eric
Cc: grassuser@grass.itc.it
Subject: Re: [GRASS-user] g.mlist newline separator request

Hi,

this patch should fix it.

But I am not sure whether to commit it to CVS. Patch seems to be
"ugly" for me, moreover I am not sure why printf fn was used in the
script (?)

Martin

2007/4/12, Patton, Eric <epatton@nrcan.gc.ca>:

I've noticed that g.mlist doesn't enter a newline after the last entry in a list, which used to be the case about a month ago:

~/coderepo >g.mlist pattern=Minas_Basin*
Minas_Basin_Jan16_2007_50m
Minas_Basin_Jan16_2007_50m_med3
Minas_Basin_Jan16_2007_50m_med3_shade
Minas_Basin_Jan16_2007_50m_med3_shade_comb
Minas_Basin_Jan16_2007_50m_shade
Minas_Basin_Jan16_2007_50m_shade_comb~/coderepo >

Consequently, any script that tries to get a count from g.mlist by piping to wc will get an incorrect count that will be off by one:

g.mlist pattern=Minas_Basin_Jan16_2007_50m | wc -l
0 (Should be 1)

g.mlist pattern=Minas_Basin* | wc -l
5 (Should be 6)

Would it be possible to get the final newline back? I have scripts that are broken now because a for loop never gets started when a check is done against the number of rasters matched:

MATCHES=`g.mlist pattern=${PATTERN} | wc -l`

# Abort if no matches are found.
if [ "$MATCHES" -eq 0 ] ; then
        echo "$SCRIPT: No rasters matched the search pattern!"
        exit 1
fi

~ Eric.

_______________________________________________
grassuser mailing list
grassuser@grass.itc.it
http://grass.itc.it/mailman/listinfo/grassuser

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *