Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Ok, I did this: Code: find . -not -name "*.mp3" -not -name "*.MP3" -type f -print >> /home/chris/fixing/tfix.txt Now I want to cat the output of tfix.txt, and mv all ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Enthusiast Weedman's Avatar
    Join Date
    May 2005
    Location
    Tasmania, Australia
    Posts
    640

    'mv'ing an output of cat


    Ok, I did this:
    Code:
    find . -not -name "*.mp3" -not -name "*.MP3" -type f -print >> /home/chris/fixing/tfix.txt
    Now I want to cat the output of tfix.txt, and mv all of that output.

    Google has prooved useless, the closest I have got is this:
    Code:
    mv (cat /home/chris/fixing/tfix.txt) /home/chris/fixing/
    and using different brackets or quotabtion marks makes no difference, it just doesn't work.

    I have tried google, and the man pages with nothing.

    Help is required,
    Thanks,

    weed
    "Time has more than one meaning, and is more than one dimension" - /.unknown
    --Registered Linux user #396583--

  2. #2
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    You wanna mv tfix.txt, or each of the filenames found?

    I'm confused.

  3. #3
    Linux Enthusiast Weedman's Avatar
    Join Date
    May 2005
    Location
    Tasmania, Australia
    Posts
    640
    for each of the filenames found.

    Thanks,

    weed
    "Time has more than one meaning, and is more than one dimension" - /.unknown
    --Registered Linux user #396583--

  4. #4
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    You will need to move them individually, so you might find using a for construct helpful.
    Code:
    for i in $(find . -not -name "*.mp3" -not -name "*.MP3" -type f -print);do mv $i ~chris/fixing/$(basename $i);done
    Note that mv requires the new filename, so if you want it to remain intact you need to restate the original name, hence "basename $i" which will return just the basic filename, without its current path. If you don't use basename you will make copies of the subdirectories as are, which you may desire instead.

  5. #5
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Well, first off, to use a command's output, you either use backticks (`), or, as I prefer, $(...) notation.

    Now, bigtomrodney's solution will work, but I personally find it confusing. If we start off after your original find command, this would work just fine:
    Code:
    exec 3< /home/chris/fixing/tfix.txt; while read line <&3; do mv "$line" "/home/chris/fixing/$(basename $line)"; done
    I personally prefer having more simpler commands over having one really complex one, so whichever of these you prefer would work.

  6. #6
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    This should work:

    Code:
    mv `cat /home/chris/fixing/tfix.txt` /home/chris/fixing/
    (as long as there are not too many files...)

    EDIT: If this is anything more than a "one-time manual thing" (i.e., in a script, for repeated use) -- I would use a more structured method - handling each file separately in a loop (which is what the other guys are suggesting).

  7. #7
    Linux Enthusiast Weedman's Avatar
    Join Date
    May 2005
    Location
    Tasmania, Australia
    Posts
    640
    Your kidding me, that simple?!?!?

    EDIT: I get no such file or directory errors on the "cat ..." section.

    weed
    "Time has more than one meaning, and is more than one dimension" - /.unknown
    --Registered Linux user #396583--

  8. #8
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Quote Originally Posted by Weedman
    EDIT: I get no such file or directory errors on the "cat ..." section.
    I'm not sure what you mean -- the 's' on 'errors' implies more than one error -- yet, if it was for 'cat', it would be one error - if it was for 'mv', it could be more than one error.

    The contents of the file '/home/chris/fixing/tfix.txt' is assumed from your 'find' command in the first post. If the file exists, 'cat' shouldn't give an error.

    If the files pointed to by the contents of '/home/chris/fixing/tfix.txt' still exist, 'mv' shouldn't give an error.


  9. #9
    Linux Enthusiast Weedman's Avatar
    Join Date
    May 2005
    Location
    Tasmania, Australia
    Posts
    640
    It's MV that's having the problems.

    It spits out this error every time:
    Code:
    mv: cannot stat `cat ./fixing/ttfix.txt': No such file or directory
    When I know that the files exist, and I am certain. I have checked the paths.

    There is something wrong with the syntax, I know it.

    weed
    "Time has more than one meaning, and is more than one dimension" - /.unknown
    --Registered Linux user #396583--

  10. #10
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    This might be silly to ask, but --- You did use a backtick (`) - not a single-quote (') - before and after the cat command, right?

    Code:
    `cat /home/chris/fixing/tfix.txt`
    EDIT: I made both of the backticks BOLD - but I don't see it...

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •