Article View: comp.lang.fortran
Article #6570Re: removing blanks from a file
From: mbbr
Date: Mon, 03 Jul 2006 08:21
Date: Mon, 03 Jul 2006 08:21
61 lines
3808 bytes
3808 bytes
Kookdancing queen, Dickless Davie tholen@antispam.ham the irrelevant Ignoranus whined and tholed: > Luka Djigas writes: > > > Greetings > > English is not my mother language, so I'd like to apologize in > > advance, if this sounds a little funny to you. > > Since fortran programmers are running thin in my part of the world, > > and since looks like there's a good deal of them here, I was wondering > > if you could help me with a little problem I'm having (searched > > google, found some half solutions but nothing concrete) > > > > I have a file, which is the output of one of my programs. It's a > > script file, and therefore it's not supposed to have blanks in it. > > The file looks something like this > > 1.0, 1.0, 1.0 > > 1.0, 1.0, 1.0 > > .... > > and it would be good if it looked like this > > 1.0,1.0,1.0 > > 1.0,1.0,1.0 > > .... > > > > I tried something like this > > > > CHARACTER(1) :: CH > > INTEGER(4) :: IOEND=0 > > OPEN(1,FILE='FILE.TXT') > > DO WHILE (IOEND/=-1) > > READ(1, "(A1)", IOSTAT=IOEND, ADVANCE="NO")CH > > IF CH=CHAR(49) > > CH=CHAR(50) > > WRITE(1, "(A1)", ADVANCE="NO")CH > > END DO > > CLOSE(1) > > END > > > > If you try it you will see that it has some drawbacks. > > > > Please, if anyone has some ideas how to solve this problem, I'd be > > very grateful, if he/she would share them. > > Use two strings, each declared with a length corresponding to the longest > line you will encounter in the file. One string will be input, the other > output. A0L! What is this shit, Dickless? You code as bad as you play. > Use two character counters, one for the input string, one for the output > string. Use a DO loop to scan each character of the input string. If > that character is a non-blank, increment the character count for the > output string and copy that character to the output string. When done > scanning that line, write the output string to the output file, perhaps > using the TRIM function to eliminate trailing blanks. Here's a better idea. Read from stdin, a character at a time, and write to stdout except when the character is a blank. You can do that in FORTRAN can't you, Dickless? Or use sed, awk, tr, or whatever Unix tool you wish. No wait, you don't have stuff like that in your dead OS/2 do you, Dickless?
Technical Details
Message-ID:
<1151914869.536470.65280@j8g2000cwa.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!j8g2000cwa.googlegroups.com!not-for-mailReferences:
<f6o8a2l6ocspufkmmi2kdb7rs4msupld07@4ax.com> <2FZog.21774$uy3.17421@tornado.socal.rr.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1094ba,810ae8d3fc4c92d1 X-Google-Thread: 1138ec,29d0b57d333919c9,start X-Google-Thread: 102c26,29d0b57d333919c9,start X-Google-Thread: 1156f6,29d0b57d333919c9,start X-Google-Attributes: gid1094ba,gid1138ec,gid102c26,gid1156f6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!j8g2000cwa.googlegroups.com!not-for-mail From: mbbr@mighty.co.za Newsgroups: comp.lang.fortran,comp.os.os2.advocacy,rec.music.classical,demon.local Subject: Re: removing blanks from a file Date: 3 Jul 2006 01:21:09 -0700 Organization: http://groups.google.com Lines: 62 Message-ID: <1151914869.536470.65280@j8g2000cwa.googlegroups.com> References: <f6o8a2l6ocspufkmmi2kdb7rs4msupld07@4ax.com> <2FZog.21774$uy3.17421@tornado.socal.rr.com> NNTP-Posting-Host: 210.211.117.172 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1151914873 20971 127.0.0.1 (3 Jul 2006 08:21:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 3 Jul 2006 08:21:13 +0000 (UTC) In-Reply-To: <2FZog.21774$uy3.17421@tornado.socal.rr.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: j8g2000cwa.googlegroups.com; posting-host=210.211.117.172; posting-account=gfDFhQ0AAAD-2SlsgA4JCYtc0KAvRvTc