tags:

views:

104

answers:

2

This is a follow-up to this question's answer.

How can I modify the code so that the annoying CRLF of a DOS created file can be stripped away before being passed to xargs?

Example file 'arglist.dos'.

# cat > arglist.unix
src/file1 dst/file1
src/file2 dst/file2
src/file3 dst/file3
^c
# sed 's/$/\r/' arglist.unix > arglist.dos

The unix variant of the file works with this:

$ xargs -n2 < arglist.unix echo cp
cp src/file1 dst/file1
cp src/file2 dst/file2
cp src/file3 dst/file3

For my own education, how can I change it to accept either the 'arglist.unix' or 'arglist.dos' files on the same command line?

+1  A: 

Use d2u to remove the CR before passing the file to xargs.

David Harris
On my system, it's called `dos2unix`
Dennis Williamson
Different name; same functionality.
David Harris
I'd prefer to do it on the same command line, does `d2u`/`dos2unix` support that?
Jamie
As with many unix commands, when invoked without parameters, dos2unix operates on stdin and stdout.
Jeremy Stein
+1  A: 
cat arglist.dos | tr -d "\r" | xargs -n2 echo cp

gives you the same result as

cat arglist.unix | tr -d "\r" | xargs -n2 echo cp

so it works on both files.

tr -d "\r" removes all the CR characters

Puppe
Thanks. I guess what I was after was an understanding of the `<` operator in the original command line; you're example makes it clear to me that `xargs` is taking it's input from `stdin` in both yours an my versions.
Jamie