home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!bnrmtl.bnr.ca!pat
- From: pat@bnrmtl.bnr.ca
- Newsgroups: comp.unix.questions
- Date: 17 Jul 92 22:23 MDT
- Subject: Re: A Couple of Last Minute Odds 'n End
- Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
- Message-ID: <1992Jul17.182308.29660@bnrmtl.bn>
- References: <1992Jul17.120738.27558@ncsu.edu>
- Nf-ID: #R:1992Jul17.120738.27558@ncsu.edu:2114388534:1992Jul17.182308.29660@bnrmtl.bn:-1940795653:001:2538
- Nf-From: bnrmtl.bnr.ca!pat Jul 17 22:23:00 1992
- Lines: 88
-
-
- [Sorry for the repost. _Again_ I messed up the Distribution:]
-
- In article <1992Jul17.120738.27558@ncsu.edu>, bregenma@gate.ncsu.edu (Bradley Regenman) writes:
- | ... Now, however, if the next line is non-blank,
- | it is to be assumed that it is a continuation. In other
- | words:
- |
- | description of example | IOTA, KAPPA, LAMBDA, MU,
- | NU, XI
- |
- | another example description | OMICRON PI RHO SIGMA
- | TAU
- |
- | a shorter example description | TAU, UPSILON
- |
- | Also, commas may or may not be used. The only
- | question I have is how to concatenate the next line to the
- | previous one if it's non-blank.
-
- How about this:
-
- > cat foo
- description of example | IOTA, KAPPA, LAMBDA, MU,
- NU, XI
-
- another example description | OMICRON PI RHO SIGMA
- TAU
-
- a shorter example description | TAU, UPSILON
-
- > awk '{ printf "%s ", $0 } NF == 0 { print "\n" }' foo
- description of example | IOTA, KAPPA, LAMBDA, MU, NU, XI
-
- another example description | OMICRON PI RHO SIGMA TAU
-
- a shorter example description | TAU, UPSILON
-
- >
-
- It does add some unecessary blanks to the file, but that's
- probably not serious.
-
-
- | sed "s/ALPHA/$alpha/" "$infile" |
- | sed "s/BETA/$beta/" |
- | sed "s/DELTA/$delta/" |
- | [ ~25 more ]
- | sed "s/OMEGA/$omega/" > "$wkfile"
-
- You only need one sed command to do all these changes:
-
- sed -e "s/ALPHA/$alpha/" \
- -e "s/BETA/$beta/" \
- ...
- -e "s/OMEGA/$omega/" \
- "$infile" > "$wkfile"
-
- This should be somewhat faster than using multiple sed commands.
-
-
- | So... I tried this (from Patrick Smith):
- |
- | awk '{ for ( i = 1; i <= NF; i++ ) print NR, $i }' ${1+"$@"} \
- | | sort +0n +1n \
- | | awk 'NR != 1 && $1 != last { printf "\n" }
- | $1 == last { printf ", " }
- | { printf "%d", $2; last = $1 }
- | END { printf "\n" }'
- |
- | When I put it in a file by itself and ran it on test data, it ran
- | correctly. However, when I inserted it into my program, I got
- | dozens of pages (literally) of '0,0,0,0' ... as output. So...
-
- Strange. Did you forget to replace ${1+"@"} with the name of your
- input file? (Or remove it completely if you're taking the input
- from a pipe.)
-
- For faster solutions in awk and C, see another posting of mine.
- You may need to modify the programs slightly to handle blank
- lines in the input correctly.
-
-
- --
- Patrick Smith preferred: larry.mcrcim.mcgill.edu!bnrmtl!pat
- Bell-Northern Research next best: patrick@bnr.ca
- (514) 765-7914
-
-