peman Posted March 30, 2004 Report Share Posted March 30, 2004 (edited) Hi I need to know how to create several files in one command line? I want to have ch01 ch02 ch03... and so on up to ch14 Is'nt the touch command? I also want to know how to create several files with content like author or something like that. Thanks! :) Edited March 30, 2004 by peman Quote Link to comment Share on other sites More sharing options...
feralertx Posted March 31, 2004 Report Share Posted March 31, 2004 Hope this helps, at least for the first part. Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 1, 2004 Report Share Posted April 1, 2004 uh, uh, i think i know this one... its not as complex as what gAru would propose but this should be enough... #!/bin/bash ctr=0 stop=14 while [ $ctr -lt $stop ] do touch "file$ctr" ctr=`expr $ctr + 1` done ciao! Quote Link to comment Share on other sites More sharing options...
aru Posted April 2, 2004 Report Share Posted April 2, 2004 I couldn't resist, ramfree + bash, my two favorite discussion topics :P While ramfree's advice is 100% correct, I would have done it using a "for" loop: #! /bin/bash for ((i=1; i<=14; ++i)); # or for i in $(seq 14); do touch $(printf "ch%02d" $i) done The printf stuff allows you to name the files as you wanted: ~/example$ ./thisscript ~/example$ ls ch01 ch03 ch05 ch07 ch09 ch11 ch13 ch02 ch04 ch06 ch08 ch10 ch12 ch14 If you want to include, for example the author name on each file, then instead of using the touch command just replace that line with this one: echo "Author: Myself" > $(printf "ch%02d" $i) Hence, on each file you'll have that text ; ie: ~/example$ cat ch01 Author: Myself HTH Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted April 2, 2004 Report Share Posted April 2, 2004 Quote Link to comment Share on other sites More sharing options...
Qchem Posted April 2, 2004 Report Share Posted April 2, 2004 gah, thats just too good - I was thinking about this and probably would have reached for sed instead of echo - KISS (to me)!!! Quote Link to comment Share on other sites More sharing options...
aru Posted April 2, 2004 Report Share Posted April 2, 2004 Your comments cant be good for my ego, sure :P Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 5, 2004 Report Share Posted April 5, 2004 bah! a simple question flooded by bash elitism. kidding aside, i wouldnt have thought of that solution. :woops: ciao! Quote Link to comment Share on other sites More sharing options...
iphitus Posted April 5, 2004 Report Share Posted April 5, 2004 whoa, hey aru, ive got a pile of mp3s and they are unfortunately sorted into folders of the artist then subfolders of the album, how can i put all the mp3s in one directory? Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 6, 2004 Report Share Posted April 6, 2004 just move everything to a directory? you could use find+xargs to copy them over. or lets wait gAru to whip up something that also arranges them according to genre ciao! Quote Link to comment Share on other sites More sharing options...
aru Posted April 6, 2004 Report Share Posted April 6, 2004 (edited) just move everything to a directory? you could use find+xargs to copy them over. Though right, it could be done w/o xargs: ~$ find basedir/ -iname "*.mp3" -exec bash -c 'mv $1 DEST_DIR/' {} {} \; or lets wait gAru to whip up something that also arranges them according to genre ciao! That's simple :P just replace DEST_DIR with the output of mp3info -p '%g' mp3file; the problem is that all the mp3 should have a coherent genre value (if not, you might end with a new directory for each mp3, and of course, it must have a valid ID3 tag. For example, this would be (not tested): ~$ find basedir/ -iname "*.mp3" -exec bash -c 'GENRE_DIR=$(mp3info -p "%g" $1); [ "${GENRE_DIR}" == "" ] && GENRE_DIR=no_genre_dir/; mkdir -p "$GENRE_DIR"; mv $1 "$GENRE_DIR/"' {} {} \; trivial, isn't it? Edited April 6, 2004 by aru Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 6, 2004 Report Share Posted April 6, 2004 ~$ find basedir/ -iname "*.mp3" -exec bash -c 'GENRE_DIR=$(mp3info -p "%g" $1); [ "${GENRE_DIR}" == "" ] && GENRE_DIR=no_genre_dir/; mkdir -p "$GENRE_DIR"; mv $1 "$GENRE_DIR/"' {} {} \;<!--QuoteEBegin--> trivial, isn't it? NUTS!!!! Quote Link to comment Share on other sites More sharing options...
aru Posted April 6, 2004 Report Share Posted April 6, 2004 (edited) you shouldn't put on proof THE MASTER!! :mmmwwwaaaahahahahaha PS: I've added your blog to my bookmarks, it promises Edited April 6, 2004 by aru Quote Link to comment Share on other sites More sharing options...
ramfree17 Posted April 6, 2004 Report Share Posted April 6, 2004 you shouldn't put on proof THE MASTER!! :mmmwwwaaaahahahahaha PS: I've added your blog to my bookmarks, it promises too much offtopic... i just replied here. B) ciao! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.