Results 1 to 4 of 4

Thread: Been done before? (before I waste my time)

  1. #1
    Very good friend of the forum Virchanza's Avatar
    Join Date
    Jan 2010
    Posts
    863

    Default Been done before? (before I waste my time)

    I'm thinking of coding a program but I dunno if it's been done before so I wanna ask here first before I waste my time.

    Take a program like "find" that prints strings to the screen. Let's say you want to perform an operation on every string that it prints, and let's say that the operation is as follows:

    rm X

    (where X is the string that comes out of "find")

    Well the idea is that I'd have a program called "many" that you use as follows:

    find | many rm X

    What it does is perform the operation "rm X" on every string that gets printed by "find".

    I came up with this idea because I was moving all my stuff from my MSWindows partition across to my Linux partition (I'm abandoning MSWindows in favour of Linux). So anyway, my Windows folders had all sorts of stupid names like "My Videos", so I wanted a quick way of doing the following to every file and directory:
    1) Replace uppercase characters with lowercase
    2) Replace spaces with underscores
    3) Remove "My " at the start

    To do the filename conversion, I could have an extremely simple little command line program that takes an input such as "My Home Videos" and gives the output as "home_videos". Let's say this program is call "name_linifier".

    It would be great to be able to use "name_linifier" as follows:

    find | many mv X `name_linifier X`

    Does such a program already exist? It would be so immensely useful that I get the idea it's been done before, but if it hasn't then I'll get coding it right away.

    (By the way I realise I'll have a little problem parsing `name_linifier X` but it won't be a problem, I've already got a workaround in mind, I can just replace the apostrophe character with some other character of choice)
    Ask questions on the open forums, that way everybody benefits from the solution, and everybody can be corrected when they make mistakes. Don't send me private messages asking questions that should be asked on the open forums, I won't respond. I decline all "Friend Requests".

  2. #2
    Member
    Join Date
    Sep 2008
    Posts
    306

    Default

    Hey Virchanza,
    first thing i would recommend you change the tite , it isn't very descriptive.

    To your question , doesn't sed perform a part of your project?
    I think it's possible to combine it with other commands (direct or by script).

    And at all , don't you think it would be faster to do it by hand than writing a program for it?

    Cheers,
    terminal
    Be sensitive in choosing where you ask your question. You are likely to be ignored, or written off as a loser, if you:

    * post your question to a forum where it's off topic
    * post a very elementary question to a forum where advanced technical questions are expected, or vice-versa
    * cross-post to too many different newsgroups
    * post a personal e-mail to somebody who is neither an acquaintance of yours nor personally responsible for solving your problem

  3. #3
    Very good friend of the forum Virchanza's Avatar
    Join Date
    Jan 2010
    Posts
    863

    Default

    Just to be clear, the project in question is "many", not "name_linifier".

    Quote Originally Posted by terminal86 View Post
    To your question , doesn't sed perform a part of your project?
    Perhaps it does, I haven't used "sed" before but I've read a little bit about it in Linux tutorials.

    I think it's possible to combine it with other commands (direct or by script)
    Basically I'm looking for a way to execute a command on every string that gets outputed from a program, so to create an individual folder for each of your groups, you could do:

    groups | many mkdir X

    And at all , don't you think it would be faster to do it by hand than writing a program for it?
    Not really I'd quite a few files. Anyway the idea is that this will be reusable, not only by me but by the whole *nix community.
    Ask questions on the open forums, that way everybody benefits from the solution, and everybody can be corrected when they make mistakes. Don't send me private messages asking questions that should be asked on the open forums, I won't respond. I decline all "Friend Requests".

  4. #4
    Very good friend of the forum Virchanza's Avatar
    Join Date
    Jan 2010
    Posts
    863

    Default

    Never mind, I have since learned that this can be done quite easily using "xargs" in conjunction with scripts.

    For instance, you could write a script as follows:

    Code:
    mv $0 `name_linifier $0`
    and then use it as follows:

    Code:
    find | xargs name_linifier
    It does exactly what I'm looking for, plus you have the freedom of scripting to make it do whatever you want.
    Ask questions on the open forums, that way everybody benefits from the solution, and everybody can be corrected when they make mistakes. Don't send me private messages asking questions that should be asked on the open forums, I won't respond. I decline all "Friend Requests".

Posting Permissions

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