Professional Web Applications Themes

Newbie question - Linux / Unix Administration

I have a newbie question. What command I use to see if there are any extra spaces with in the line by using grep? I assumed I would look for all line that didn't have a 0-9 a-z A-Z? Is this how I would do that and how would the command read? Thanks for your help....

  1. #1

    Default Newbie question

    I have a newbie question. What command I use to see if there are any
    extra spaces with in the line by using grep? I assumed I would look
    for all line that didn't have a 0-9 a-z A-Z? Is this how I would do
    that and how would the command read? Thanks for your help.

    WebGod@aol.com Guest

  2. #2

    Default Re: Newbie question

    In article <googlegroups.com>,
    com wrote:
     

    What are "extra" spaces? How many spaces can you have before the rest
    are considered extra?
     

    grep ' ' filename

    will show all the lines in the file that have any spaces in them.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  3. #3

    Default Re: Newbie question

    On 2005-10-17, com wrote: 

    What do you mean by "extra spaces"?
     

    Is that what you want to do?
     

    If you want to find lines that contain nothing but whitespace
    (spaces and tabs):

    grep '^[ ][ ]*$' FILENAME

    Each pair of brackets contains a space and a tab.


    If you want do do it for a single line, you don't need grep:

    case $line in
    *[! ]*) echo "Not just whitespace" ;;
    *) echo "Just whitespace" ;;
    esac

    --
    Chris F.A. Johnson <http://cfaj.freeshell.org>
    ================================================== ================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>
    Chris Guest

  4. #4

    Default Re: Newbie question

    Excellent! Thank you for your help. Also, I apologize for the
    multiple postings. Thanks again!

    WebGod@aol.com Guest

  5. #5

    Default Re: Newbie question

    Sorry I ended that post early...To continue with my question. What I
    meant by extra spaces is say I am typing a sentence and I put more
    than one space in between like in this sentence within a file. How do
    I find that line in the file using grep? Thanks again!

    WebGod@aol.com Guest

  6. #6

    Default Re: Newbie question

    Chris F.A. Johnson wrote: [/ref]

    School is back in session and folks are trying to be
    creative in getting others to do their homework, right?
    Deal is there's an expectation of tit-for-tat. Folks
    with a long history of contribution get a lot better
    response than newbies. Folks with interesting questions
    get a lot better response than folks with questions that
    sound like homework.
     
    >
    > What do you mean by "extra spaces"?[/ref]

    I figured a single space separates words, a double
    space separates sentences, trailing spaces on a line are
    always extra, and something sensible should be done
    about indentation at the start of paragraphs.

    So you'll want to grep for multiple spaces and pipe
    that into a grep -v of punctuation followed by two
    spaces. That second one is nice practice for regular
    expressions. Then you'll want to learn that the dollar
    sign is used in regular expressions to stand for end
    of line so you can detect trailing spaces. Then you'll
    want to learn that caret is used in regular expressions
    to stand for start of line so you can detect
    indentation.
     [/ref]

    I'm not convinced that empty lines (see caret and dollar
    above) are bad. I am convinced that space-only lines are
    bad. Detecting a line with only multiple spaces is
    another nice use of regular expressions, brackets and
    stars this time.

    Done well, the question actually uses some fancy REs to
    get it to work. Gotta know which punctuation to escape,
    how to handle n-tuple repeats of spaces. Even better is
    handling anything but a tab as the start of a paragraph
    because that also includes the line before it must be
    empty (can't do two lines in a row with only grep in
    normal cirstances).

    Doug Guest

  7. #7

    Default Re: Newbie question

    In article <googlegroups.com>,
    com wrote:
     

    So you want to find two spaces in a row, or three spaces at the end of a
    sentence? Something like this will do it:

    egrep '[.!?] |[^.!?] ' filename

    This doesn't handle the case where the end of a sentence is inside
    quotes, like:

    He said, "Damn!" And then he shut up.

    It will complain about this because it thinks those spaces are in the
    middle of a sentence, not at the end. Correcting it is left as an
    exercise for the reader.

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  8. #8

    Default Re: Newbie question

    What I think is needed is simpler than I assumed it would be. If I
    have a list of things like this:
    Sam and Dave
    Jack and Jill
    Harold and Maude
    I should be able to find the extra spaces between and and Jill above
    By using grep '[ ][ ]' filename
    This should search for any space, followed by any other space with
    nothing in between, correct? Thanks for all your help.

    WebGod@aol.com Guest

  9. #9

    Default Re: Newbie question

    com wrote:
     
    I guess he hasn't gotten to the awk part of grep/sed/awk...
    Alan Guest

  10. #10

    Default Re: Newbie question

    com writes:
     

    Off topic perhaps, but someone said:
    "The sentence:
    'There should be hyphens between Fish and and and and and Chips
    in my Fish and Chips sign' would be clearer if there quotes
    before Fish and between Fish and and and and and and and and
    and and and and and and and and and and and and and Chips and
    after Chips."

    /Niklas Norrthon
    Niklas Guest

  11. #11

    Default Re: Newbie question

    On 2005-10-18, Alan D Johnson wrote: 
    > I guess he hasn't gotten to the awk part of grep/sed/awk...[/ref]

    He hasn't even got to the part of explaining exactly what he
    wants.

    Once he describes exactly what that is, the solution will be
    obvious.

    --
    Chris F.A. Johnson <http://cfaj.freeshell.org>
    ================================================== ================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>
    Chris Guest

  12. #12

    Default Re: Newbie question

    com wrote: 

    grep ' ' filename
    will find all lines that contain two consecutive spaces.

    You only need the [abc] notation to match *one* of several specific
    different characters; 'a' or 'b' or 'c' in this example.

    man grep. (and possibly man regexp depending on O/S)
    Have you considered buying an introductory book on Unix?


    Ian Guest

  13. #13

    Default Re: Newbie question

    On Tue, 18 Oct 2005 01:10:04 GMT, Alan D Johnson <rr.com> wrote: [/ref]
     

    Well, to be fair, I found it rather awkward when I started as well.

    Dave "Get it? I sed 'awk'ward. It's like humor...nevermind..." Hinz

    Dave Guest

  14. #14

    Default Re: Newbie question

    Begin <net>
    On 2005-10-19, Dave Hinz <net> wrote: 
    [snip: aoler on usenet? I thought aol decided to drop it?] 
    >
    > Well, to be fair, I found it rather awkward when I started as well.
    >
    > Dave "Get it? I sed 'awk'ward. It's like humor...nevermind..." Hinz[/ref]

    It's also sed that if you can grep this you're awkfully awkvanced.


    --
    j p d (at) d s b (dot) t u d e l f t (dot) n l .
    Ok, I'll stop now.
    jpd Guest

  15. #15

    Default Newbie question

    We have a DG-UX print queue which defaults to 66 pages per line. How do I
    change this to 64? I have tried running lpadmin -dprintqueuename -o
    length=64 filename but it doesn't change it - any ideas?

    Thanks.


    ewenalexander Guest

Similar Threads

  1. Newbie Question: Biz Card Template Question
    By Thomas_Porter@adobeforums.com in forum Adobe Indesign Windows
    Replies: 4
    Last Post: May 30th, 08:08 AM
  2. A newbie with a newbie question
    By dusty_davis@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 5
    Last Post: October 14th, 07:54 AM
  3. a newbie question(network question)
    By hardemr in forum MySQL
    Replies: 2
    Last Post: February 2nd, 06:08 PM
  4. Replies: 5
    Last Post: December 3rd, 10:44 AM
  5. Pen Tool Use Question. (Embarrassingly Newbie Question)
    By Bozo Schmozo in forum Macromedia Flash
    Replies: 0
    Last Post: November 12th, 10:00 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139