[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: How to truncat





Norman Bauman wrote:
I have a file in XyWrite (3.55) which contains entries like the following, each one a single line ended by a carrier return. I would like to get a file in which each of the lines is truncated, after about 12 or 16 characters. (The reason is that I want to sort them and find the unique journal abbreviations.) I have about 500 lines so it would be tedious to do it by hand. Is there an easy way to truncate lines like this, using simple functions of XyWrite, DOS utilities, or the usual programs I'm likely to have around? I could write a XyWrite macro to define the first few words in the file, and copy it to a second file, since some of the publication names are 3 or 4 words. Or I could have a macro start define, cursor over N spaces, end define, and copy it to a second file. But that sounds clunky. There should be an easy way. SciAm, Feb 2002, Down with the bad, up with the good, Thomas Maeder. Vaccines to enzymes on the cholesterol cascade raise HDL and lower LDL in rabbits, and are now in phase II trials. NEJM, 24 Jan 2002, 346(4), CHOP chemotherapy plus rituximab in elderly patients with diffuse large B-cell lymphoma, B. Coiffier et al. Cyclophosphamide, doxorubicin, vincristine and prednisone (CHOP) were used with and without rituximab. The response with rituximab was significantly higher. JAMA, 23/30 Jan 2002, 287(4), Chelation therapy for ischemic heart disease: a randomized controlled trial, Merril L. Knudtson et al. "There is no evidence to support a beneficial effect of chelation therapy in patients with ischemic heart disease, stable angina, and a positive treadmill test for ischemia."
Norman Download the djgpp(dos) version of the GNU text utilities from "http://www.simtel.net/pub/djgpp/v2gnu/txt20b.zip; to your local directory, "c:\local", say. (These utilities are free.) Unzip "txt20b.zip" in "c:\local", letting the unzipper generate default subdirectories. (Any of winzip, gzip, pkzip, powerarchiver, etc. should work.) In "c:\local\bin", you'll find exe files, one being "cut.exe". If I understand your problem correctly, "cut" can give you the trim you need. To get a synopsis of its command line parameters, execute it with the argument "--help", i.e., "cut --help". The other programs in "bin" work similarly--check em out. Also, the "info" directory has a file you can read with a text editor if you want more info on the programs in "bin"--it's all text but with imbedded text commands used by GNU's "info" program for formatting the file for display. If your file is "ahairyfile" and you want to trim off the first 15mm (characters) of each hair (line), then "cut -c 1-15 ahairyfile" should do the trick. The above command will write the results to the screen (stdout--standard output) so, to save the output to another file such as, "togetatrim", redirect it by entering: "cut -c 1-15 ahairyfile > togetatrim" Other styles can be had by using with the "-c" parameter, values similar to "1,3,5,10-15,22" (no embedded spaces). For example, "cut -c 1,3,5,10-15,22 ahairyfile > togetatrim" gives you a more, shaggy look. :-) Regards, Lowell Anderson