Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 15 of 15
Originally Posted by chaosless i tried copying the file as you'd posted it - but the ... sequences were saved as special characters (hex: e2 80 a6) instead of 3 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Aug 2010
    Location
    Rochester, NY USA
    Posts
    9

    Quote Originally Posted by chaosless View Post
    i tried copying the file as you'd posted it - but the ... sequences were saved as special characters (hex: e2 80 a6) instead of 3 periods/points (hex: 2e 2e 2e)

    are you certain in your file that these are actually 3 regular characters that match the \. notation in sed?
    The three dots are supplied to me as a single character (elipses). Instead, try the short sample.txt: 1.e4 e5 2.Nf3 Nc6 3.c3 d5 4.Qa4 Bd7!? 5.exd5 Nd4 6.Qd1 Nxf3 7.Qxf3 Nf6 8.Bc4 e4 9.Qe2 Bd6 10.d4! {Many old books consider only 10.d3 here.} ...O-O 11.Bg5 h6 12.Bh4 Re8 13.Nd2 e3?! 14.fxe3 {it\'s best to accept} ...Bf4 15.Nf1

  2. #12
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    the elipses seemed to be one of two sequences, also found another sequences representing ' character. script below deals with the characters as i'd found them.

    my approach was to separate move lines in the sed script (chess.sed) - perhaps the matching sequence for comments could be simplified now to \[.*\] also...

    sed -f chess.sed chess.txt

    Code:
    1,2n
    s_\.\.\._@_g
    s_\xe2\x80\xa6_@_g
    s_\xe2\x80\x93_@_g
    s_\xe2\x80\x99_'_g
    s_\([0-9]\+\)\.[ \t]*\([a-zA-Z]\+[0-9]\+[?!+]*\)[ \t]*\(\[[a-zA-Z0-9 \.,'\@()?!+]*\]\)\?[ \t]*\([a-zA-Z]\+[0-9O\-]\+[?!+]*\)\?[ \t]*\(\[[a-zA-Z0-9 \.,'\@()?!+]*\]\)\?[ \t]*_\1. \2 \3 \4 \5\n_g
    this should accept O-O or 0-0 notation.

    all ... are replaced with @ to ease searching for instances without preceding move numbers - in which case the current move number is now first on the line.

    this last part i'd do in awk because have not successfully made sed do subtraction. hope that helps.
    Last edited by chaosless; 08-17-2010 at 08:54 PM. Reason: fix my confusing comment

  3. #13
    Just Joined!
    Join Date
    Aug 2010
    Location
    Rochester, NY USA
    Posts
    9
    Thank you for your help. I used some of the syntax here to upgrade my rediculous sed code. I will have to think about learning awk but it looks very difficult.

  4. #14
    Linux Engineer Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    773
    awk is like sed, but has also scripting and parsing functionality that enables it to handle CB/CF grammars and not only regular expressions. if you have the time and are interested, you should spend it and learn awk. it's even more kewl than "less is more"!

  5. #15
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    if you have been grappling with sed - would think you find awk to be wonderfully freeing. has a mix of pattern matching and procedural coding ability that i find much more powerful, but it does really expect data in lines/records - hence the reordering of the file in the sed script. by choosing to use column separators in the sed output - you could readily search only certain columns (like comments on the white or black move) for the @ (as substitute for elipse).

    still there are some jobs where i break out sed - often the right answer is a mixture of both. if you can post another example of the notation where you wish to intercede the white's move number i'll try to fill in the awk part.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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