0

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?

2 Answers 2

1
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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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

3 Comments

Different name; same functionality.
I'd prefer to do it on the same command line, does d2u/dos2unix support that?
As with many unix commands, when invoked without parameters, dos2unix operates on stdin and stdout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.