Article 6PF3H [SOLVED] problem using sed diff and xargs in single command

[SOLVED] problem using sed diff and xargs in single command

by
hopeless_n00b
from LinuxQuestions.org on (#6PF3H)
I want to diff a bunch of files (I need help with the approach I'm taking, not advice as to using some alternate method) and at this point I managed:

$ cat /mnt/usb/foo | sed -e 's@.*\(\..*\)@\/mnt\/usb\/\\\1 ~/\\\1@'
/mnt/usb/\.viminfo ~/\.viminfo
/mnt/usb/\.asoundrc ~/\.asoundrc
/mnt/usb/\.asoundrc~ ~/\.asoundrc~
/mnt/usb/\.Xresources ~/\.Xresources
/mnt/usb/\.bashrc~ ~/\.bashrc~
/mnt/usb/\.Xresources~ ~/\.Xresources~
/mnt/usb/\.0 ~/\.0
/mnt/usb/\.bash_profile ~/\.bash_profile
/mnt/usb/\.asoundrc-old ~/\.asoundrc-old
/mnt/usb/\.bashrc ~/\.bashrc
/mnt/usb/\.Xmodmap_change_usr-share-keymaps-i386_as_well ~/\.Xmodmap_change_usr-share-keymaps-i386_as_well
/mnt/usb/\.Xauthority ~/\.Xauthority
/mnt/usb/\.xdvirc ~/\.xdvirc
/mnt/usb/\.wget-hsts ~/\.wget-hsts
/mnt/usb/\.lesshst ~/\.lesshst
/mnt/usb/\.asoundrc-marg ~/\.asoundrc-marg
/mnt/usb/\.bash_logout ~/\.bash_logout
/mnt/usb/\.Xdefaults ~/\.Xdefaults
/mnt/usb/\.xinitrc ~/\.xinitrc
/mnt/usb/\.asoundrc-old~ ~/\.asoundrc-old~
/mnt/usb/\.gnuplot_history ~/\.gnuplot_history
/mnt/usb/\.asoundrc-marg~ ~/\.asoundrc-marg~
/mnt/usb/\.bash_history ~/\.bash_history

As can be seen, the above contains multiple lines each of which contains (two) paths to files (the files I want to diff). If I use the mouse to cut-and-paste a line from above so as to supply arguments to diff, then all is well:

$ diff /mnt/usb/\.asoundrc ~/\.asoundrc
0a1,3
> # aplay -l
> # aplay -L
>
35c38
< pcm "hw:4,0"
---
> pcm "hw:3,0"
62c65
< # ls -l track0?.wav | sed -n -e 's/.*dpaddy dpaddy \(.*\)Aug.*/\1 + /p' | sed ':a;N;s/\n//;ta'
\ No newline at end of file
---
> # ls -l track0?.wav | sed -n -e 's/.*dpaddy dpaddy \(.*\)Aug.*/\1 + /p' | sed ':a;N;s/\n//;ta'

However, attempting to automate with xargs (so as to avoid multiple cutting and pasting) fails as follows with diff complaining:

$ cat /mnt/usb/foo | sed -e 's@.*\(\..*\)@\/mnt\/usb\/\\\1 ~/\\\1@' | xargs -n2 diff
diff: ~/.viminfo: No such file or directory
diff: ~/.asoundrc: No such file or directory
diff: ~/.asoundrc~: No such file or directory
diff: ~/.Xresources: No such file or directory
diff: ~/.bashrc~: No such file or directory
diff: ~/.Xresources~: No such file or directory
diff: /mnt/usb/.0: No such file or directory
diff: ~/.0: No such file or directory
diff: ~/.bash_profile: No such file or directory
diff: ~/.asoundrc-old: No such file or directory
diff: ~/.bashrc: No such file or directory
diff: ~/.Xmodmap_change_usr-share-keymaps-i386_as_well: No such file or directory
diff: ~/.Xauthority: No such file or directory
diff: ~/.xdvirc: No such file or directory
diff: ~/.wget-hsts: No such file or directory
diff: ~/.lesshst: No such file or directory
diff: ~/.asoundrc-marg: No such file or directory
diff: ~/.bash_logout: No such file or directory
diff: ~/.Xdefaults: No such file or directory
diff: ~/.xinitrc: No such file or directory
diff: ~/.asoundrc-old~: No such file or directory
diff: ~/.gnuplot_history: No such file or directory
diff: ~/.asoundrc-marg~: No such file or directory
diff: ~/.bash_history: No such file or directory

This is quite puzzling as ls -a reports that the files exist; for example:

$ ls -a ~/.asoundrc
/home/dpaddy/.asoundrc

Something seems horribly wrong here, why does diff think files are missing? Please help
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments