1

The below "one liner" explains what I'm trying to do:

pbpaste > ~/Documents/convertme.txt; \
dos2unix -c mac ~/Documents/convertme.txt && \
cat ~/Documents/convertme.txt | pbcopy && \
rm -vfr ~/Documents/convertme.txt

I don't like creating a temporary file, I would rather everything be handled in memory through piping the input/output all the way through.

Something like:

pbpaste | dos2unix -c mac -n /dev/stdin /dev/stdout | pbcopy

Which does not work, it errors: dos2unix: Skipping /dev/stdin, output file /dev/stdout is a symbolic link.

The only other solution I thought of was perhaps creating a shell script to handle this with variables... but I thought I'd ask here because I figured there might still be a way to pipe into and out of dos2unix.

I've searched all over StackOverflow and cannot find a duplicate question, however I'm sure there is a command similar to dos2unix which somebody has worked this flow out for. If that is the case, I'll accept an answer with that link but please also re-write the answer with dos2unix written out in the proper piped command (for future readers and those like me who can't find this indexed in google).

Jeremy Iglehart
  • 3,307
  • 2
  • 22
  • 31
  • You can't find a duplicate because your question is off topic here. Questions about Unix usage should instead be asked on https://unix.stackexchange.com/ – Rob Mar 05 '19 at 12:02
  • 1
    Maybe use a stream editor such as `tr`, `sed` or Perl instead. – Mark Setchell Mar 05 '19 at 12:09
  • Thanks for the suggestion of posting this question there @Rob This question equally applies to Mac, Unix, BSD - really any bash environment - as well as Virtual Computing in general since it's usefull in the transfer of a clipboard from an OS running in a VM environment. I think StackOverflow is general enough to ask the question rather than it just being a unix thing. Maybe maybe I'm wrong. – Jeremy Iglehart Mar 05 '19 at 20:01

1 Answers1

3

When you don't provide any input/output file names dos2unix will take input from stdin and write to stdout.

pbpaste | dos2unix -c mac | pbcopy
  1. pbpaste takes the contents of the clipboard and sends it to stdin
  2. dos2unix converts dos eol's to unix (or in this case mac). If you don't mention a file name as input, it'll take stdin.
  3. pbcopy takes stdout and pushes into the clipboard.
JohnnyLambada
  • 11,732
  • 10
  • 52
  • 59