LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Cut Text from Webpage - Weather (https://www.linuxquestions.org/questions/debian-26/cut-text-from-webpage-weather-4175449801/)

vk4led 02-12-2013 06:09 AM

Cut Text from Webpage - Weather
 
Howdy

I have a script that works well with retreiving weather information from a webpage. If then tailors it to how I want it then spits it out as email.

I have the script working under CentOS, however I have just converted it over to Debian

The script works all the way up until it is required to "cut" information obtained and place it into a file for editing.

************************* FROM SCRIPT ******************

echo "Location supplied = "$place
echo "------------------------------------"
interest=0
while read line; do # loop to step through pages
pagenumber=`echo $line | cut -b 0-8`
pagename=`echo $line | cut -b 11-`
echo "Scanning -----> "$pagenumber" <----- "
**************************************************************

It gets to the "cut" section and spits out"

cut: fields and positions are numbers from 1
Try `cut --help' for more information

I am sure there is a simple answer for this, however I am puzzled as to why it falters on this "cut" command - when it was working so well under CentOS

Many thanks for reading this.

Guttorm 02-12-2013 07:35 AM

Hi

This line is buggy:

Quote:

pagenumber=`echo $line | cut -b 0-8`
That cut command take a range of bytes, 1 meaning the first byte. So using 0 here is incorrect.

http://linux.die.net/man/1/cut

It doesn't say what should happen if the numbers are incorrect. My guess is that some other versions of cut simply ignores it, and uses 1 instead, while others give an error message.

Try changing the line to this:

Quote:

pagenumber=`echo $line | cut -b 1-8`

vk4led 02-12-2013 03:59 PM

Thanks for the short and swift answer! Funny how some of these things you keep looking at and it is staring you right in the face!

Appreciated


All times are GMT -5. The time now is 03:06 AM.