Shell scripting - duplicate text
I'm trying to find a simple way to move all of my music into subdirectories.
Step 1 - make the directories.
I did this with the following 1 liner:
Code:
ls -ld * | grep -v drwx | awk '{print $8, $9, $10, $11}' | grep '-' | cut -d'-' -f1 | uniq -i > make_dirs.sh
I then used some simple search routines in vi to have this listing create the directories:
Code:
%s/^/mkdir "/g
%s/$/"/g
That way, for every band there is an entry:
Step 2 - move files into directories.
This is where I run into trouble. I am trying to do something similar. I have again output the same bandnames to a file, and am trying to find a way to double the text on each line:
Band Name -> Band Name Band Name
The final goal is:
Code:
mv "Band Name"* "Band Name"/.
Effectively moving all files into the folders.
I thought I would start in vi with the following search/replace:
%s/$/"* "/g
Giving me:
Band Name"* "
I then thought I might be able to use cut to duplicate:
cat make_dirs.sh | cut -d"\"" -f1,2,3,1
printing the
1. Band Name
2. "*
3. "
1. Band Name
But unfortunately, it doesn't repeat printing the first field.
Any ideas?
Ubuntu 8.04 Hardy Heron
BIOSTAR TFORCE 550 Socket AM2 NVIDIA nForce 550 MCP ATX AMD MOBO, AMD Athlon 64 X2 3600+ w/ Arctic Cooling Alpine 64, 3x512MB DDR2 800 OCZ Gold SDRAM, Gigabyte GeForce 7300GT 256MB GDDR2, 160GB SATA 120GB PATA
Bookmarks