SED question
I need to print any lines that have contain 11 for November or 12 for December.
My two questions are:
How do I search for more than one item I.E. print lines with the value 11 and 12?
How do I tell the search to look in column 4 which has the dates?
What I have so far:
sed -n -e '/11/,/12/p' datebook
File datebook:
Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300
Betty Boop:245-836-8357:635 Cutesy Lane, Hollywood, CA 91464:6/23/23:14500
Igor Chevsky:385-375-8395:3567 Populus Place, Caldwell, NJ 23875:6/18/68:23400
Norma Corder:397-857-2735:74 Pine Street, Dearborn, MI 23874:3/28/45:245700
Jennifer Cowan:548-834-2348:583 Laurel Ave., Kingsville, TX 83745:10/1/35:58900
Jon DeLoach:408-253-3122:123 Park St., San Jose, CA 04086:7/25/53:85100
Karen Evich:284-758-2857:23 Edgecliff Place, Lincoln, NB 92086:7/25/53:85100
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
Fred Fardbarkle:674-843-1385:20 Parak Lane, DeLuth, MN 23850:4/12/23:780900
Fred Fardbarkle:674-843-1385:20 Parak Lane, DeLuth, MN 23850:4/12/23:780900
Lori Gortz:327-832-5728:3465 Mirlo Street, Peabody, MA 34756:10/2/65:35200
Paco Gutierrez:835-365-1284:454 Easy Street, Decatur, IL 75732:2/28/53:123500
Ephram Hardy:293-259-5395:235 CarltonLane, Joliet, IL 73858:8/12/20:56700
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
Barbara Kertz:385-573-8326:832 Ponce Drive, Gary, IN 83756:12/1/46:268500
Lesley Kirstin:408-456-1234:4 Harvard Square, Boston, MA 02133:4/22/62:52600
William Kopf:846-836-2837:6937 Ware Road, Milton, PA 93756:9/21/46:43500
Sir Lancelot:837-835-8257:474 Camelot Boulevard, Bath, WY 28356:5/13/69:24500
Jesse Neal:408-233-8971:45 Rose Terrace, San Francisco, CA 92303:2/3/36:25000
Zippy Pinhead:834-823-8319:2356 Bizarro Ave., Farmount, IL 84357:1/1/67:89500
Arthur Putie:923-835-8745:23 Wimp Lane, Kensington, DL 38758:8/31/69:126000
Popeye Sailor:156-454-3322:945 Bluto Street, Anywhere, USA 29358:3/19/35:22350
Jose Santiago:385-898-8357:38 Fife Way, Abilene, TX 39673:1/5/58:95600
Tommy Savage:408-724-0140:1222 Oxbow Court, Sunnyvale, CA 94087:5/19/66:34200
Yukio Takeshida:387-827-1095:13 Uno Lane, Ashville, NC 23556:7/1/29:57000
Vinh Tranh:438-910-7449:8235 Maple Street, Wilmington, VM 29085:9/23/63:68900
How do I tell the search to look in column 4 which has the dates?
This is an indication that you should use awk because sed doesn't have the concept of fields. An awk solution would be
awk -v FS=":" '$4 ~ /^1[12]\/.*/{print}' datebook
Output
Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
Barbara Kertz:385-573-8326:832 Ponce Drive, Gary, IN 83756:12/1/46:268500
Deciphering the solution
FS=":" sets the the field/column delimiter to colon.
$4 represents the column four in your input file which is the date in the format mm/dd/yy
The ~ in $4 ~ /^1[12]\/.*/ means we do a regex match in which
^ represents the beginning of the string
[12] can match either one or two.
Since the regex part itself is delimited by / you need to escape any literal / as in \/
It appears that you want to select lines where the first characters after the third colon on the line are 11/ or 12/ (since the data formats appear to be pre-Y2K-style US-format dates with mm/dd/yy notation). So you write:
$ sed -n '/^\([^:]*:\)\{3\}1[12]\//p' datebook
Steve Blenheim:238-923-7366:95 Latham Lane, Easton, PA 83755:11/12/56:20300
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
Karen Evich:284-758-2867:23 Edgecliff Place, Lincoln, NB 92743:11/3/35:58200
James Ikeda:834-938-8376:23445 Aster Ave., Allentown, NJ 83745:12/1/38:45000
Barbara Kertz:385-573-8326:832 Ponce Drive, Gary, IN 83756:12/1/46:268500
$
The ^ matches at the start of a line; the \([^:]*]:\) part looks for a series of zero or more non-colons followed by a colon; the \{3\} requires 3 of them; the 1[12]\/ demands 11/ or 12/ after that; the p prints.
I observe that the initial statement says 'contain 11 for November or 12 for December', but your first numbered question says 'value 11 and 12'. These are contradictory; a given date field can only start with one or the other, not both. I've assumed that 'or' is what you intended.
I'd like to parse a complex CSV file. I searched sources on the web but I only found readers for simple csv with coma and quote marks. But mine also contains "{", "[" and ":" in order to create groups, subgroups...
How can I retrieve a proper NSArray or a NSDictionary from this kind of csv ?
Or do you know a great (great !) csv reader/parser ?
Thanks !
Here is an example :
{"meta":{"code":200},"response":{"groups":[{"type":"nearby","name":"À
proximité","items":[{"id":"4bc88ad72f94d13aa9c5137f","name":"Métro
Chaussée d'Antin - La Fayette
[7,9]","contact":{},"location":{"address":"Métro
Chaussée d'Antin - La
Fayette","city":"Paris","state":"Île
de
France","postalCode":"75009","lat":48.872908,"lng":2.33325,"distance":39},"categories":[{"id":"4bf58dd8d48988d1fd931735","name":"Subways","icon":"http://foursquare.com/img/categories/travel/subway.png","parents":["Travel
Spots"],"primary":true}],"verified":false,"stats":{"checkinsCount":885,"usersCount":368},"hereNow":{"count":0}},{"id":"4ba8e508f964a520e4f739e3","name":"AdenClassifieds","contact":{},"location":{"address":"1-3
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8733461,"lng":2.3340489,"distance":50},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":187,"usersCount":29},"hereNow":{"count":0}},{"id":"4c10cd34b4aeef3bad5afc0f","name":"AdenSourcing","contact":{},"location":{"address":"1,
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.873009,"lng":2.333263,"distance":28},"categories":[{"id":"4bf58dd8d48988d125941735","name":"Tech
Startups","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"],"primary":true},{"id":"4bf58dd8d48988d174941735","name":"Coworking
Spaces","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"]}],"verified":false,"stats":{"checkinsCount":60,"usersCount":7},"hereNow":{"count":0}},{"id":"4b6d79c2f964a520f6762ce3","name":"Négatif+","contact":{},"location":{"address":"106
rue
lafayette","city":"Paris","state":"France","postalCode":"75010","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d1ff941735","name":"Miscellaneous
Shops","icon":"http://foursquare.com/img/categories/shops/default.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":121,"usersCount":51},"hereNow":{"count":0}},{"id":"4beeb21a2c082d7f96b53042","name":"Sephora
Haussmann","contact":{},"location":{"address":"23
bd
Hausmann","city":"Paris","state":"Ile-de-France","lat":48.8728835,"lng":2.3334661,"distance":41},"categories":[{"id":"4bf58dd8d48988d10c951735","name":"Cosmetics
Shops","icon":"http://foursquare.com/img/categories/shops/beauty_cosmetic.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":135,"usersCount":75},"hereNow":{"count":0}},{"id":"4af55e08f964a520f3f821e3","name":"Chez
Jean","contact":{},"location":{"address":"4
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8731558,"lng":2.3334978,"distance":13},"categories":[{"id":"4bf58dd8d48988d118951735","name":"Grocery
Stores","icon":"http://foursquare.com/img/categories/shops/food_grocery.png","parents":["Shops","Food and Drink
Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":46,"usersCount":27},"hereNow":{"count":0}},{"id":"4bee9a52e8c3c928dfd89892","name":"H&M","contact":{},"location":{"lat":48.872951,"lng":2.333551,"distance":35},"categories":[{"id":"4bf58dd8d48988d104951735","name":"Boutiques","icon":"http://foursquare.com/img/categories/shops/apparel.png","parents":["Shops","Clothing
Stores"],"primary":true}],"verified":false,"stats":{"checkinsCount":84,"usersCount":66},"hereNow":{"count":0}},{"id":"4b51d04df964a520865627e3","name":"Surcouf","contact":{},"location":{"address":"21,
bd
Haussmann","city":"Paris","state":"France","postalCode":"75009","lat":48.8728008,"lng":2.3339615,"distance":65},"categories":[{"id":"4bf58dd8d48988d122951735","name":"High
Tech
Outlets","icon":"http://foursquare.com/img/categories/shops/technology.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":332,"usersCount":194},"hereNow":{"count":0}},{"id":"4b1e6795f964a5209a1924e3","name":"Le
Manoir","contact":{},"location":{"address":"34
Boulevard
Haussmann","city":"Paris","state":"France","postalCode":"75009","lat":48.872964707066394,"lng":2.334015369415283,"distance":56},"categories":[{"id":"4bf58dd8d48988d16d941735","name":"Cafés","icon":"http://foursquare.com/img/categories/food/cafe.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":116,"usersCount":61},"hereNow":{"count":0}},{"id":"4cb59ee81b0af04dca42ca25","name":"Casa
Del
Campo","contact":{},"location":{"address":"Rue
Lafayette","city":"Paris","state":"Ile-de-France","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d1db931735","name":"Tapas
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":12,"usersCount":11},"hereNow":{"count":0}},{"id":"4cdd43c0d5495481874446b2","name":"Thalys
Paris >
Bruxelles","contact":{},"location":{"address":"111
rue
Lafayette","city":"Paris","state":"Ile-de-France","postalCode":"75011","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d12a951735","name":"Trains","icon":"http://foursquare.com/img/categories/travel/trainstation.png","parents":["Travel
Spots","Train
Stations"],"primary":true}],"verified":false,"stats":{"checkinsCount":5,"usersCount":5},"hereNow":{"count":0}},{"id":"4ba3d477f964a520226438e3","name":"Les
Diamantaires","contact":{},"location":{"address":"60,
Rue
Lafayette","city":"Paris","state":"Ile-de-France","postalCode":"75009","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d115941735","name":"Middle
Eastern
Restaurants","icon":"http://foursquare.com/img/categories/food/middleeastern.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":11,"usersCount":10},"hereNow":{"count":0}},{"id":"4cbeb94297bc721e31158167","name":"Dentiste","contact":{},"location":{"address":"36
bd
haussmann","city":"Paris","state":"Ile-de-France","lat":48.8729985,"lng":2.3331688,"distance":31},"categories":[{"id":"4bf58dd8d48988d178941735","name":"Dentist's
Offices","icon":"http://foursquare.com/img/categories/building/medical_dentist.png","parents":["Homes,
Work, Others","Medical
Centers"],"primary":true}],"verified":false,"stats":{"checkinsCount":9,"usersCount":2},"hereNow":{"count":0}},{"id":"4c098514bbc676b0365c48d5","name":"Best
Place To Be
Naked","contact":{},"location":{"lat":48.872859,"lng":2.333289,"distance":43},"categories":[],"verified":false,"stats":{"checkinsCount":36,"usersCount":21},"hereNow":{"count":0}},{"id":"4bbc55912d9ea5937878a0ce","name":"Pizza
Tivoli","contact":{},"location":{"address":"5
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8733461,"lng":2.3340489,"distance":50},"categories":[{"id":"4bf58dd8d48988d110941735","name":"Italian
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":62,"usersCount":47},"hereNow":{"count":0}},{"id":"4be11bf20f03a593908e18b4","name":"Pole
Direction Nvx
Medias","contact":{},"location":{"lat":48.872878,"lng":2.333277,"distance":42},"categories":[],"verified":false,"stats":{"checkinsCount":25,"usersCount":6},"hereNow":{"count":0}},{"id":"4c17d044834e2d7f94f02780","name":"Josefin","contact":{},"location":{"city":"Paris","state":"Ile-de-France","lat":48.872863,"lng":2.333273,"distance":43},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":14,"usersCount":8},"hereNow":{"count":0}},{"id":"4b597cfcf964a520e68928e3","name":"Siege
Danone","contact":{},"location":{"address":"17
boulevard
hausmann","city":"Paris","lat":48.873557,"lng":2.334042,"distance":59},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":23,"usersCount":13},"hereNow":{"count":0}},{"id":"4c1f5058fcf8c9b6f66bae0b","name":"Obene","contact":{},"location":{"address":"35
rue saint
lazarre","city":"Paris","state":"Francr","postalCode":"75009","lat":48.872829,"lng":2.333201,"distance":48},"categories":[{"id":"4bf58dd8d48988d1c0941735","name":"Mediterranean
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":21,"usersCount":5},"hereNow":{"count":0}},{"id":"4d5133ac9ffc236a026720a7","name":"Sofa
Cafe
Studio","contact":{},"location":{"lat":48.873568,"lng":2.33384,"distance":48},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":11,"usersCount":10},"hereNow":{"count":0}},{"id":"4cfa4adf2d80a1438a9f43d8","name":"Manucurist","contact":{},"location":{"address":"Rue
de la chausse d
antin","city":"Paris","state":"Ile-de-France","lat":48.87294352054596,"lng":2.333693504333496,"distance":41},"categories":[{"id":"4bf58dd8d48988d10c951735","name":"Cosmetics
Shops","icon":"http://foursquare.com/img/categories/shops/beauty_cosmetic.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":28,"usersCount":4},"hereNow":{"count":0}},{"id":"4c7b90c9794e224bb48d6b28","name":"Le
Galfa - La
Fayette","contact":{},"location":{"lat":48.872853,"lng":2.333072,"distance":49},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":20,"usersCount":15},"hereNow":{"count":0}},{"id":"4c124b6377cea59338bccc60","name":"Noon","contact":{},"location":{"address":"Rue
de la chaussee d
antin","city":"Paris","state":"Ile-de-France","lat":48.8736428,"lng":2.3330026,"distance":51},"categories":[{"id":"4bf58dd8d48988d146941735","name":"Delis
or
Bodegas","icon":"http://foursquare.com/img/categories/food/deli.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":15,"usersCount":12},"hereNow":{"count":0}},{"id":"4bb2f78ea32876b0173a01fe","name":"Glam
Media France (temp
Offices)","contact":{},"location":{"address":"21
bd
Haussman","city":"Paris","lat":48.87305,"lng":2.333831,"distance":39},"categories":[{"id":"4bf58dd8d48988d125941735","name":"Tech
Startups","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"],"primary":true}],"verified":false,"stats":{"checkinsCount":7,"usersCount":4},"hereNow":{"count":0}},{"id":"4c122cd7583c9c74bf323fa4","name":"Havaianas
welcomes Summer # Galeries
Lafayette","contact":{"phone":"0142823456","twitter":"havaianaseurope"},"location":{"address":"40
boulevard Haussmann","city":"75009
Paris","state":"France","country":"France","lat":48.8731566,"lng":2.3327878,"distance":44},"categories":[{"id":"4bf58dd8d48988d107951735","name":"Shoe
Stores","icon":"http://foursquare.com/img/categories/shops/apparel.png","parents":["Shops","Clothing
Stores"],"primary":true}],"verified":true,"stats":{"checkinsCount":11,"usersCount":9},"hereNow":{"count":0}},{"id":"4b9a40c4f964a52081a735e3","name":"little
georgette","contact":{},"location":{"lat":48.872544,"lng":2.33322,"distance":79},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":60,"usersCount":41},"hereNow":{"count":0}},{"id":"4c319736213c2d7f5e33345d","name":"Isiom","contact":{},"location":{"lat":48.872815,"lng":2.333228,"distance":49},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":7,"usersCount":2},"hereNow":{"count":0}},{"id":"4c89f5e49ef0224b0595567b","name":"Cardiweb","contact":{},"location":{"city":"Paris","state":"Ile-de-France","lat":48.873727,"lng":2.33362,"distance":55},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":5,"usersCount":3},"hereNow":{"count":0}},{"id":"4c507cf7991c20a18e014786","name":"Focus
Groups","contact":{},"location":{"lat":48.872982,"lng":2.33353,"distance":31},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":1,"usersCount":1},"hereNow":{"count":0}}]}]}}
That looks like JSON, not CSV. Use this JSON Framework to parse the file: http://code.google.com/p/json-framework/