Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
This is my script but i wonder why it display error like.. head: unrecognized option `-:' Try `head --help' for more information. sed: -e expression #1, char 14: unknown option ...
  1. #1
    Just Joined!
    Join Date
    Jul 2007
    Posts
    59

    Need help in grep, head and tail

    This is my script but i wonder why it display error like..

    head: unrecognized option `-:'
    Try `head --help' for more information.
    sed: -e expression #1, char 14: unknown option to `s'
    tail: invalid option -- 1
    Try `tail --help' for more information.


    Wonder anyone can solve this?




    The script i got here is,

    #!/bin/bash
    #code.h





    curl --proxy proxy.tp.edu.sg:80 "www.channelnewsasia.com/singapore/index.htm " > 1.txt :



    grepheader=$header:

    lines1=${2:-3}:

    lines2=${2:-1}:

    sub=$'s/<[^<>]*>//g':


    cat 1.txt | grep $grepheader | head -$lines1 | sed $sub | tail -$lines2 > data.txt:





    exit

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    What is that colon (:) doing at the end of most of the lines? Remove all of them that are at the ends of lines. But don't remove the colons that are not at the ends of lines.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    What wje_lf said (your variable is ending up with a trailing colon, which isn't numeric).

    Do you really only want to strip the tags off the last line?

    And please don't cat a file into grep - tell grep the name of the file, or redirect it to grep's stdin! Don't be a process hog!

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Posts
    59
    i have follow the code you told me to...but it still display results like...



    Try `head --help' for more information.
    tail: invalid option -- 1
    Try `tail --help' for more information.
    sed: -e expression #1, char 14: unknown option to `s'

  5. #5
    Just Joined!
    Join Date
    Jul 2007
    Posts
    59
    What do you mean by - tell grep the name of the file, or redirect it to grep's stdin! ??? Mind showing an example to me ???



    Quote Originally Posted by scm View Post
    What wje_lf said (your variable is ending up with a trailing colon, which isn't numeric).

    Do you really only want to strip the tags off the last line?

    And please don't cat a file into grep - tell grep the name of the file, or redirect it to grep's stdin! Don't be a process hog!

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Code:
    cat 1.txt | grep $grepheader
    What do you mean by - tell grep the name of the file
    Code:
    grep $grepheader 1.txt
    redirect it to grep's stdin! ???
    Code:
    grep $grepheader < 1.txt
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Jul 2007
    Posts
    59
    But no matter hw i try , i still cannot get the result i want ...'

    i try using the method grep $grepheader < 1.txt.. but still cannot work...

    can any1 help me ??





    This is what i get after i type in mty file name "./myscript ", but it display nth on my data.txt, just a plain txt only...

    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 43044 0 43044 0 0 8838 0 --:--:-- 0:00:04 --:--:-- 10943
    100 286 100 286 0 0 10409 0 --:--:-- --:--:-- --:--:-- 10409
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try `grep --help' for more information.

  8. #8
    Linux User infoshirish's Avatar
    Join Date
    May 2007
    Location
    Pune, India
    Posts
    397
    Quote Originally Posted by jeffrey_seeNJ View Post
    But no matter hw i try , i still cannot get the result i want ...'

    i try using the method grep $grepheader < 1.txt.. but still cannot work...

    can any1 help me ??





    This is what i get after i type in mty file name "./myscript ", but it display nth on my data.txt, just a plain txt only...

    &#37; Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 43044 0 43044 0 0 8838 0 --:--:-- 0:00:04 --:--:-- 10943
    100 286 100 286 0 0 10409 0 --:--:-- --:--:-- --:--:-- 10409
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try `grep --help' for more information.
    Hello,

    I guess the error simply says that your script is colliding with system head command. Just change your variable name "grepheader" and may be the "head" name comes throughout your script.
    Regards,

    who |grep -i blonde |
    date; cd~; unzip; touch;
    strip; finger; mount; gasp;
    yes; uptime; umount;
    sleep

    Newbie clicks
    http://www.linuxforums.org/forum/lin...ead-first.html

  9. #9
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I'm guessing that $header, and therefore $grepheader, is empty. This would cause your script to execute the following grep command:
    Code:
    grep
    just by itself. Not much there, is there?

    Want to see whether the header is empty? Just before the offending line in your script, insert these lines:
    Code:
    echo \$header is this: \"$header\"
    echo \$grepheader is this: \"$grepheader\"
    --
    Bill

    Old age and treachery will overcome youth and skill.

  10. #10
    Just Joined!
    Join Date
    Jul 2007
    Posts
    59
    I change the variable from grepheader to var1...but the error is still the same...hw come???







    Quote Originally Posted by infoshirish View Post
    Hello,

    I guess the error simply says that your script is colliding with system head command. Just change your variable name "grepheader" and may be the "head" name comes throughout your script.

Page 1 of 3 1 2 3 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...