Exclude a record from sort - sorting

Is there a parameter for sort programme to exclude (ignore) the first line of a file from sorting in jcl.
Thanks,

If your Sort level is up-to-date, you can use DATASORT. Borrowed from an answer by Frank Yaeger, via google.
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
FIRST
AAAA
CCCC
DDDD
FFFF
GGGG
//OUT DD SYSOUT=*
//TOOLIN DD *
DATASORT FROM(IN) TO(OUT) FIRST USING(CTL1)
/*
//CTL1CNTL DD *
SORT FIELDS=(1,4,CH,A)
/*

You can try the following:
//SYSIN DD *
SORT FIELDS=...
SKIPREC=1
/*
You may have to do a sort copy and in a subsequent JCL step do the sort.

Try using the ICETOOL SUBSET operator. Here is a really simple example:
//STEP01 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD * -- Unsorted input data...
FIRST LINE
5
6
7
1
4
/*
//TOOLIN DD * -- ICETOOL commands
SUBSET FROM(IN1) TO(OUT1) REMOVE INPUT HEADER
/*
//OUT1 DD SYSOUT=* -- Sorted output goes here
Upon completion OUT1 contains:
1
4
5
6
7
which are the data from IN1, sorted, missing the first input line.
The DFSORT/ICETOOL manual can be found here and the
ICETOOL SUBSET operator is
documented here
edit
Based on your comment to Gilbert, I suggest using a second job step to
IDCAMS REPRO (copy) the first record from the original input file and then concatenate it to the ICETOOL output. The JCL is relatively straight forward.

Related

how to limit 00 to 99 counter to 60

For a simple starter project I was putting together a 2-7segement display 00 to 99 counter coded on sketch.
//The line below is the array containing all the binary numbers for the digits on a SSD from 0 to 9
const int number[11] = {0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010, 0b0000010, 0b1111000, 0b0000000, 0b0010000};
I believe that my solution is either to change this part of the code or add another line, I'm just unsure.
Any advice?
I have tried adding another line to set one of the displays to stop at 6 but it didn't compile with the rest of the code.

How to write a JCL to send an email

How to write JCL to send an email but the content(Data) should be picked from another PDS/member. If anyone can let me know the JCL for what I need will be helpful.**
Here is an old example but it sounds like what you are looking for. It uses IEBGENER to send an e-mail. (I didn't write the content so complain to IBM if you don't like it.)
This is from Knowledge Center
//BATSMTP JOB (userid,nn),MSGCLASS=B,PRTY=12,MSGLEVEL=(2,1)
//*
//* Store message in a PDS
//*
//PUTMSG EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSUT1 DD *
HELO YOURMVS
MAIL FROM:<CAROL#YOURMVS>
RCPT TO:<msgs#rsch.our.edu>
RCPT TO:<alice#ai.our.edu>
DATA
Date: Thur, 26 Mar 92 21:48:57 EST
From: Carol <CAROL#YOURMVS>
To: <msgs#rsch.your.edu>
Cc: <alice#ai.your.edu> Subject: update
Mike: Cindy stubbed her toe. Bobby went to
baseball camp. Marsha made the cheerleading team.
Jan got glasses. Peter has an identity crisis.
Greg made dates with 3 girls and couldn't
remember their names.
.
QUIT
/*
//SYSUT2 DD DSN=MYPDS.OF.MESSAGES(MSGID1),DISP=SHR
//*
//SYSPRINT DD SYSOUT=A
//*
//* Send Message from placed in PDS in prior step
//*
//SENDMSG EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSUT1 DD DSN=MYPDS.OF.MESSAGES(MSGID1),DISP=SHR
//*
//SYSUT2 DD SYSOUT=(B,smtp)
//* | v
//* v SMTP address space name for external writer
//* SYSOUT class
//SYSPRINT DD SYSOUT=A
Concatenate your PDS member with your other stuff in SYSUT1 e.g.
//SYSUT1 DD *
your stuff here
// DD DSM=your.pds(member),DISP=SHR
`You may need other stuff after your member - just concatenate more DD *.
Remember that your PDS data must be LRECL=80
Concatenation works fine if all source data has the same DCB. If not, use SORT to create a temporary VB file with LRECL = your longest LRECL + 4. E.g., if you need to merge 80-byte PDS data with 133-byte reports, use SORT to copy everything to a VB file with LRECL=137 and send that to the sysout.
If anyone is still reading, I'd like to find out how to set up a BCC: recipient. Apparently, only TO: and CC: are supported.
Sample JCL for building the VB file:
000007 //BUILD PROC
000008 //SORT EXEC PGM=SORT
000009 //SORTOUT DD DISP=(MOD,PASS),DSN=&&EMAIL,UNIT=SYSDA,
000010 // SPACE=(CYL,(1,1)),DCB=(RECFM=VB,LRECL=430,BLKSIZE=27998)
000011 //*
000012 //SYSIN DD *
000013 OPTION COPY
000014 OUTFIL FNAMES=SORTOUT,FTOV
000015 //SORTWK01 DD SPACE=(CYL,(5,5),RLSE),UNIT=SYSDA
000016 //SORTWK02 DD SPACE=(CYL,(5,5),RLSE),UNIT=SYSDA
000017 //SORTWK03 DD SPACE=(CYL,(5,5),RLSE),UNIT=SYSDA
000018 //SORTWK04 DD SPACE=(CYL,(5,5),RLSE),UNIT=SYSDA
000019 //SORTWK05 DD SPACE=(CYL,(5,5),RLSE),UNIT=SYSDA
000020 //SYSPRINT DD SYSOUT=*
000021 //SORTMSG DD SYSOUT=*
000022 //SYSDBOUT DD SYSOUT=*
000023 //SYSUDUMP DD SYSOUT=*
000024 //SYSOUT DD SYSOUT=*
000025 //*
000026 // PEND
000027 //*
000028 //HEADER EXEC BUILD --------------------------------------------
000029 //SORT.SORTOUT DD DISP=(,PASS)
000030 //SORT.SORTIN DD *
000031 HELO MVSOSA.CAPITALONE.COM
000032 MAIL FROM:<{from address}>
000033 RCPT TO:<{to address}>
000034 DATA
000035 FROM: <{from address}>
000036 TO:<{to address>
000037 SUBJECT: {subject}
000038 MIME-Version: 1.0
000039 Content-type: multipart/mixed; boundary="=_boundary"
000040
000041 These comments don't show up in the email.
000042
000043 Note: After each boundary, one or more records describes the
000044 content that follows. After the last "Content-..." record
000045 in each section, be sure to have a blank line.
000046
000047
000049
000050 See also https://www.ibm.com/support/pages/
000051 outbound-email-attachments-using-smtp-or-cssmtp-zos
000052
000053 --=_boundary
000054 Content-Type: text/plain;
000055
000056 Good day.
000057 Please find attached the reports you wanted.
000058
000059 Regards -- Me
000060
000061 --=_boundary
000062 Content-Type: application;
000063 Content-Disposition: attachment; filename={report name}.txt
000064 Content-Transfer-Encoding: 8bit;
000065
000066 /*
000067 //STATRPT EXEC BUILD
000068 //SORT.SORTIN DD DISP=SHR,DSN={file name with report}
000069 //*
000070 //*
000071 //*-------------------------------------------------------------*
000072 //EMAILSTP EXEC PGM=IEBGENER
000073 //SYSPRINT DD SYSOUT=*
000074 //SYSIN DD DUMMY
000075 //SYSUT2 DD SYSOUT=(B,SMTP)
000076 //SYSUT1 DD DISP=(OLD,PASS),DSN=&&EMAIL
000077 //*
000078 //*==============================================================
000079 //*

Can one do the equivalent of `pread(fd, buf, size, offset)` from the shell prompt?

I'd like to do the equivalent of what I can do in C via:
pread(fdesc, tgtbuf, size, file_offset);
or the combination:
lseek(fd, file_offset, SEEK_SET);
read(fd, tgtbuf, size)
as a shell command.
For some sizes/offsets, one can use:
dd if=file bs=size skip=$((file_offset/size)) count=1
That works ... but only if file_offset is divisible by size. Which isn't sufficient for my usecase, unfortunately.
The device I'm attempting to read from is "blocked" in 8-byte units for read but allows (requires) byte offsets for seek. dd always reads in units of bs/ibs but also always seeks in these units, which in my case is mutually exclusive.
I know I can do this via perl/python/C/... - but is there a way to do this from a simple shell script ?
EDIT: Since it was suggested to use dd bs=1 count=8 ... here - NO THIS DOES NOT WORK. strace it and you'll see that this does:
$ strace -e lseek,read dd if=/dev/zero bs=1 skip=1234 count=8
[ ... ]
lseek(0, 1234, SEEK_CUR) = 0
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
read(0, "\0", 1) = 1
Which is not what I need - it must be a single read().
Edit2:
The device (/dev/cpu/<ID>/msr) I'm trying to read from is strange in the sense that the offset is treated as an index number, but you'll always have to read eight bytes else the driver gives EINVAL on read.
But every index returns a different 8-byte value, so you cannot "reconstruct" reading from offset x+1 by reading x and x+8 and extracting the bytes. This is highly unusual ... but it's the way /dev/cpu/<ID>/msr works in Linux.
bs=size : size can be 1 byte, or more ... (it is an indication to dd on how to access the device, but for a file you can use whatever you need.. it's usually more efficient reading blocks of larger sizes, though)
try:
dd if=file bs=1 skip=whateveryouneed count=8 #to read 8 bytes starting at whateveryouneed
if (contrary to what you seem to state in the question) you can only seek to multiple of 8 (and read 8 bytes from there):
dd if=file bs=8 skip=X count=1 #to read 8 bytes starting at whateveryouneed
#X being: whateveryouneed / 8 (ex: echo "4000 / 8" | bc )
(as I say in my comment, I really have troubles to imagine a device that allows you to seek anywhere, and force you to read 8 bytes from anywhere, if anywhere is not also a multiple of 8 ... but, hey, anything is possible ^^ If so, you'll need another tool than dd, i'm afraid)
If it really is so weird: extract 2 blocks of 8 bytes around the adress you need, and then extract the exact part you need from it :
blockoffset=$(($address/8))
blockstart=$(($blockoffset*8))
shift=$(($address - $blockstart))
if [ "$shift" -eq 0 ]
dd if=file bs=8 skip=$blockoffset count=1 > final
else
dd if=file bs=8 skip=$blockoffset count=2 > bigger #we read 2 blocks from blockoffset
dd if=bigger bs=1 skip=$shift count=8 > final
fi
Given the amount of trouble you've gone to already, just put the C code into an executable program. Or get really ambitious and make the program into a bash extension with "enable -f pread.so pread"
http://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
likely over the top. A separate program is easier.

Cant get JCL SORT's Outfil to work

I am learning mainframe programming (TSO, JCL, COBOL...) and I came across a problem I can't seem to solve, yet.
I have a file with records that contain 3 fields and I want to use 'outfil' to include only certain records in the output file.
My JCL is the following:
000001 //C8112J1 JOB (12345678),C8112,MSGCLASS=H,
000002 // MSGLEVEL=(1,1),NOTIFY=C8112
(...)
000007 //DSNDEL EXEC PGM=IDCAMS
000008 //SYSPRINT DD SYSOUT=*
000009 //SYSIN DD *
000010 DELETE C8112.DATA.FX.SORT
000011 SET MAXCC = 0
000012 /*
(...)
000014 //* --------- S O R T -----------
000020 //MYSORT EXEC PGM=SORT,COND=(0,NE)
000021 //SORTIN DD DSN=C8112.DATA.FX,DISP=SHR
000022 //SORTOUT DD DSN=C8112.DATA.FX.SORT,
000023 // SPACE=(TRK,(100,100),RLSE),
000024 // DISP=(NEW,CATLG,DELETE),
000025 // DCB=(LRECL=61,RECFM=FB)
000026 //SYSIN DD *
000027 SORT FIELDS=COPY
000028 //* SORT FIELDS=(1,18,CH,A) OU SORT=COPY
000029 OUTFIL INCLUDE=(1,18,CH,EQ,C'ANDRADE,LUISA')
...
000031 //* OUTREC=(39,41,1,18,19,38)
000032 END
000033 //SYSOUT DD SYSOUT=*
000034 /*
and the output file:
000001 LUIS,CARLOS AV.PAULO VI RMR
000002 DIAS,PATTY RUA PEDRO CALMON LX
000003 ANDRADE,LUISA AV. DA LIBERDADE LX (1)
000004 SILVA,TONI PALACIO VALMOR LX
000005 ANDRADE,LUISA AV. DA BOAVISTA POT (2)
000006 CISCO,MANUEL QUINTA DA AVELEDA TC
Wasn't I supposed to get only the records (1) and (2)?! By the way, I also tried the 'outrec' to change the bytes organization but it didn't work too.
Can anyone give me a hint on what I am doing wrong?
You can use a single * as a comment delimiter in DFSORT rather than //* - which, as has already been pointed out terminates the SYSIN just as if you'd coded /. (You indeed have a / later on, I notice.)
Try the following:
000020 //MYSORT EXEC PGM=SORT,COND=(0,NE)
000021 //SORTIN DD DSN=C8112.DATA.FX,DISP=SHR
000022 //SORTOUT DD DSN=C8112.DATA.FX.SORT,
000023 // SPACE=(TRK,(100,100),RLSE),
000024 // DISP=(NEW,CATLG,DELETE),
000025 // DCB=(LRECL=61,RECFM=FB)
000026 //SYSIN DD *
000027 SORT FIELDS=COPY
000029 OUTFIL INCLUDE=(1,18,CH,EQ,C'ANDRADE,LUISA')
...
000032 END
000031 /*
000033 //SYSOUT DD SYSOUT=*
000034 //*
SORT SYSIN does not allow for "comments". Those lines you thought might have been comments really are't. They terminate the SYSIN DD statements. Basically I just got rid of:
//* SORT FIELDS=(1,18,CH,A) OU SORT=COPY
and
//* OUTREC=(39,41,1,18,19,38)
then it all works fine. Remember, a JCL comment is not a SORT comment! The stuff after a DD * are data, not JCL source statements so JCL type commenting conventions do not work here. The DD * is typically terminated by a line starting with: /*.

Code Golf: Duplicate Character Removal in String

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvkn
Example Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvkn
Example Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
LabVIEW 7.1
ONE character and that is the blue constant '1' in the block diagram.
I swear, the input was copy and paste ;-)
http://i25.tinypic.com/hvc4mp.png
http://i26.tinypic.com/5pnas.png
Perl
21 characters of perl, 31 to invoke, 36 total keystrokes (counting shift and final return):
perl -pe's/$1//gwhile/(.).*\1/'
Ruby — 61 53 51 56 35
61 chars, the ruler says. (Gives me an idea for another code golf...)
puts ((i=gets.split(''))-i.select{|c|i.to_s.count(c)<2}).join
+-------------------------------------------------------------------------+
|| | | | | | | | | | | | | | | |
|0 10 20 30 40 50 60 70 |
| |
+-------------------------------------------------------------------------+
gets.chars{|c|$><<c[$_.count(c)-1]}
... 35 by Nakilon
APL
23 characters:
(((1+ρx)-(ϕx)ιx)=xιx)/x
I'm an APL newbie (learned it yesterday), so be kind -- this is certainly not the most efficient way to do it. I'm ashamed I didn't beat Perl by very much.
Then again, maybe it says something when the most natural way for a newbie to solve this problem in APL was still more concise than any other solution in any language so far.
Python:
s=raw_input()
print filter(lambda c:s.count(c)<2,s)
This is a complete working program, reading from and writing to the console. The one-liner version can be directly used from the command line
python -c 's=raw_input();print filter(lambda c:s.count(c)<2,s)'
J (16 12 characters)
(~.{~[:I.1=#/.~)
Example:
(~.{~[:I.1=#/.~) 'nbHHkRvrXbvkn'
RrX
It only needs the parenthesis to be executed tacitly. If put in a verb, the actual code itself would be 14 characters.
There certainly are smarter ways to do this.
EDIT: The smarter way in question:
(~.#~1=#/.~) 'nbHHkRvrXbvkn'
RrX
12 characters, only 10 if set in a verb. I still hate the fact that it's going through the list twice, once to count (#/.) and another to return uniques (nub or ~.), but even nubcount, a standard verb in the 'misc' library does it twice.
Haskell
There's surely shorter ways to do this in Haskell, but:
Prelude Data.List> let h y=[x|x<-y,(<2).length$filter(==x)y]
Prelude Data.List> h "nbHHkRvrXbvkn"
"RrX"
Ignoring the let, since it's only required for function declarations in GHCi, we have h y=[x|x<-y,(<2).length$filter(==x)y], which is 37 characters (this ties the current "core" Python of "".join(c for c in s if s.count(c)<2), and it's virtually the same code anyway).
If you want to make a whole program out of it,
h y=[x|x<-y,(<2).length$filter(==x)y]
main=interact h
$ echo "nbHHkRvrXbvkn" | runghc tmp.hs
RrX
$ wc -c tmp.hs
54 tmp.hs
Or we can knock off one character this way:
main=interact(\y->[x|x<-y,(<2).length$filter(==x)y])
$ echo "nbHHkRvrXbvkn" | runghc tmp2.hs
RrX
$ wc -c tmp2.hs
53 tmp2.hs
It operates on all of stdin, not line-by-line, but that seems acceptable IMO.
C89 (106 characters)
This one uses a completely different method than my original answer. Interestingly, after writing it and then looking at another answer, I saw the methods were very similar. Credits to caf for coming up with this method before me.
b[256];l;x;main(c){while((c=getchar())>=0)b[c]=b[c]?1:--l;
for(;x-->l;)for(c=256;c;)b[--c]-x?0:putchar(c);}
On one line, it's 58+48 = 106 bytes.
C89 (173 characters)
This was my original answer. As said in the comments, it doesn't work too well...
#include<stdio.h>
main(l,s){char*b,*d;for(b=l=s=0;l==s;s+=fread(b+s,1,9,stdin))b=realloc(b,l+=9)
;d=b;for(l=0;l<s;++d)if(!memchr(b,*d,l)&!memchr(d+1,*d,s-l++-1))putchar(*d);}
On two lines, it's 17+1+78+77 = 173 bytes.
C#
65 Characters:
new String(h.Where(x=>h.IndexOf(x)==h.LastIndexOf(x)).ToArray());
67 Characters with reassignment:
h=new String(h.Where(x=>h.IndexOf(x)==h.LastIndexOf(x)).ToArray());
C#
new string(input.GroupBy(c => c).Where(g => g.Count() == 1).ToArray());
71 characters
PHP (136 characters)
<?PHP
function q($x){return $x<2;}echo implode(array_keys(array_filter(
array_count_values(str_split(stream_get_contents(STDIN))),'q')));
On one line, it's 5+1+65+65 = 136 bytes. Using PHP 5.3 you could save a few bytes making the function anonymous, but I can't test that now. Perhaps something like:
<?PHP
echo implode(array_keys(array_filter(array_count_values(str_split(
stream_get_contents(STDIN))),function($x){return $x<2;})));
That's 5+1+66+59 = 131 bytes.
another APL solution
As a dynamic function (18 charachters)
{(1+=/¨(ω∘∊¨ω))/ω}
line assuming that input is in variable x (16 characters):
(1+=/¨(x∘∊¨x))/x
VB.NET
For Each c In s : s = IIf(s.LastIndexOf(c) <> s.IndexOf(c), s.Replace(CStr(c), Nothing), s) : Next
Granted, VB is not the optimal language to try to save characters, but the line comes out to 98 characters.
PowerShell
61 characters. Where $s="nbHHkRvrXbvkn" and $a is the result.
$h=#{}
($c=[char[]]$s)|%{$h[$_]++}
$c|%{if($h[$_]-eq1){$a+=$_}}
Fully functioning parameterized script:
param($s)
$h=#{}
($c=[char[]]$s)|%{$h[$_]++}
$c|%{if($h[$_]-eq1){$a+=$_}}
$a
C: 83 89 93 99 101 characters
O(n2) time.
Limited to 999 characters.
Only works in 32-bit mode (due to not #include-ing <stdio.h> (costs 18 chars) making the return type of gets being interpreted as an int and chopping off half of the address bits).
Shows a friendly "warning: this program uses gets(), which is unsafe." on Macs.
.
main(){char s[999],*c=gets(s);for(;*c;c++)strchr(s,*c)-strrchr(s,*c)||putchar(*c);}
(and this similar 82-chars version takes input via the command line:
main(char*c,char**S){for(c=*++S;*c;c++)strchr(*S,*c)-strrchr(*S,*c)||putchar(*c);}
)
Golfscript(sym) - 15
.`{\{=}+,,(!}+,
+-------------------------------------------------------------------------+
|| | | | | | | | | | | | | | | |
|0 10 20 30 40 50 60 70 |
| |
+-------------------------------------------------------------------------+
Haskell
(just knocking a few characters off Mark Rushakoff's effort, I'd rather it was posted as a comment on his)
h y=[x|x<-y,[_]<-[filter(==x)y]]
which is better Haskell idiom but maybe harder to follow for non-Haskellers than this:
h y=[z|x<-y,[z]<-[filter(==x)y]]
Edit to add an explanation for hiena and others:
I'll assume you understand Mark's version, so I'll just cover the change. Mark's expression:
(<2).length $ filter (==x) y
filters y to get the list of elements that == x, finds the length of that list and makes sure it's less than two. (in fact it must be length one, but ==1 is longer than <2 ) My version:
[z] <- [filter(==x)y]
does the same filter, then puts the resulting list into a list as the only element. Now the arrow (meant to look like set inclusion!) says "for every element of the RHS list in turn, call that element [z]". [z] is the list containing the single element z, so the element "filter(==x)y" can only be called "[z]" if it contains exactly one element. Otherwise it gets discarded and is never used as a value of z. So the z's (which are returned on the left of the | in the list comprehension) are exactly the x's that make the filter return a list of length one.
That was my second version, my first version returns x instead of z - because they're the same anyway - and renames z to _ which is the Haskell symbol for "this value isn't going to be used so I'm not going to complicate my code by giving it a name".
Javascript 1.8
s.split('').filter(function (o,i,a) a.filter(function(p) o===p).length <2 ).join('');
or alternately- similar to the python example:
[s[c] for (c in s) if (s.split("").filter(function(p) s[c]===p).length <2)].join('');
TCL
123 chars. It might be possible to get it shorter, but this is good enough for me.
proc h {i {r {}}} {foreach c [split $i {}] {if {[llength [split $i $c]]==2} {set r $r$c}}
return $r}
puts [h [gets stdin]]
C
Full program in C, 141 bytes (counting newlines).
#include<stdio.h>
c,n[256],o,i=1;main(){for(;c-EOF;c=getchar())c-EOF?n[c]=n[c]?-1:o++:0;for(;i<o;i++)for(c=0;c<256;c++)n[c]-i?0:putchar(c);}
Scala
54 chars for the method body only, 66 with (statically typed) method declaration:
def s(s:String)=(""/:s)((a,b)=>if(s.filter(c=>c==b).size>1)a else a+b)
Ruby
63 chars.
puts (t=gets.split(//)).map{|i|t.count(i)>1?nil:i}.compact.join
VB.NET / LINQ
96 characters for complete working statement
Dim p=New String((From c In"nbHHkRvrXbvkn"Group c By c Into i=Count Where i=1 Select c).ToArray)
Complete working statement, with original string and the VB Specific "Pretty listing (reformatting of code" turned off, at 96 characters, non-working statement without original string at 84 characters.
(Please make sure your code works before answering. Thank you.)
C
(1st version: 112 characters; 2nd version: 107 characters)
k[256],o[100000],p,c;main(){while((c=getchar())!=-1)++k[o[p++]=c];for(c=0;c<p;c++)if(k[o[c]]==1)putchar(o[c]);}
That's
/* #include <stdio.h> */
/* int */ k[256], o[100000], p, c;
/* int */ main(/* void */) {
while((c=getchar()) != -1/*EOF*/) {
++k[o[p++] = /*(unsigned char)*/c];
}
for(c=0; c<p; c++) {
if(k[o[c]] == 1) {
putchar(o[c]);
}
}
/* return 0; */
}
Because getchar() returns int and putchar accepts int, the #include can 'safely' be removed.
Without the include, EOF is not defined, so I used -1 instead (and gained a char).
This program only works as intended for inputs with less than 100000 characters!
Version 2, with thanks to strager
107 characters
#ifdef NICE_LAYOUT
#include <stdio.h>
/* global variables are initialized to 0 */
int char_count[256]; /* k in the other layout */
int char_order[999999]; /* o ... */
int char_index; /* p */
int main(int ch_n_loop, char **dummy) /* c */
/* variable with 2 uses */
{
(void)dummy; /* make warning about unused variable go away */
while ((ch_n_loop = getchar()) >= 0) /* EOF is, by definition, negative */
{
++char_count[ ( char_order[char_index++] = ch_n_loop ) ];
/* assignment, and increment, inside the array index */
}
/* reuse ch_n_loop */
for (ch_n_loop = 0; ch_n_loop < char_index; ch_n_loop++) {
(char_count[char_order[ch_n_loop]] - 1) ? 0 : putchar(char_order[ch_n_loop]);
}
return 0;
}
#else
k[256],o[999999],p;main(c){while((c=getchar())>=0)++k[o[p++]=c];for(c=0;c<p;c++)k[o[c]]-1?0:putchar(o[c]);}
#endif
Javascript 1.6
s.match(/(.)(?=.*\1)/g).map(function(m){s=s.replace(RegExp(m,'g'),'')})
Shorter than the previously posted Javascript 1.8 solution (71 chars vs 85)
Assembler
Tested with WinXP DOS box (cmd.exe):
xchg cx,bp
std
mov al,2
rep stosb
inc cl
l0: ; to save a byte, I've encoded the instruction to exit the program into the
; low byte of the offset in the following instruction:
lea si,[di+01c3h]
push si
l1: mov dx,bp
mov ah,6
int 21h
jz l2
mov bl,al
shr byte ptr [di+bx],cl
jz l1
inc si
mov [si],bx
jmp l1
l2: pop si
l3: inc si
mov bl,[si]
cmp bl,bh
je l0+2
cmp [di+bx],cl
jne l3
mov dl,bl
mov ah,2
int 21h
jmp l3
Assembles to 53 bytes. Reads standard input and writes results to standard output, eg:
programname < input > output
PHP
118 characters actual code (plus 6 characters for the PHP block tag):
<?php
$s=trim(fgets(STDIN));$x='';while(strlen($s)){$t=str_replace($s[0],'',substr($s,1),$c);$x.=$c?'':$s[0];$s=$t;}echo$x;
C# (53 Characters)
Where s is your input string:
new string(s.Where(c=>s.Count(h=>h==c)<2).ToArray());
Or 59 with re-assignment:
var a=new string(s.Where(c=>s.Count(h=>h==c)<2).ToArray());
Haskell Pointfree
import Data.List
import Control.Monad
import Control.Arrow
main=interact$liftM2(\\)nub$ap(\\)nub
The whole program is 97 characters, but the real meat is just 23 characters. The rest is just imports and bringing the function into the IO monad. In ghci with the modules loaded it's just
(liftM2(\\)nub$ap(\\)nub) "nbHHkRvrXbvkn"
In even more ridiculous pointfree style (pointless style?):
main=interact$liftM2 ap liftM2 ap(\\)nub
It's a bit longer though at 26 chars for the function itself.
Shell/Coreutils, 37 Characters
fold -w1|sort|uniq -u|paste -s -d ''

Resources