Results 1 to 6 of 6
Hi
how do you copy an entire line and add that copy at the end of the same line?
For example, sometimes I rename a collection of files with a ...
- 02-06-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 2
How to copy line to itself?
Hi
how do you copy an entire line and add that copy at the end of the same line?
For example, sometimes I rename a collection of files with a command like:
"mv oldfilename newfilename;"
I am able to add "mv" at the beginning, the semicolon at the end and sometimes replace a word in the middle, but... how to change a line "oldfilename" into "oldfilename oldfilename"... that is already long time a mystery to me...
Thanks a lot already in advance!
- 02-06-2011 #2Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
You can store your string in a variable,
And then echo it twice,Code:uname@ubuntu:~$ s="oldfilename"
Although I may have misunderstood your question. What exactly do you want to do?Code:uname@ubuntu:~$ echo $s $s
- 02-07-2011 #3
in case you want to batch rename files, it could also be done with which uses perl expressions:
man rename
- 02-08-2011 #4Just Joined!
- Join Date
- Dec 2010
- Posts
- 16
That's for renaming.Code:[~]$ mkdir test [~]$ cd test [test]$ touch file1 file2 file3 [test]$ ls -1d * | tee - | sort | xargs --max-args=2 | sed -e 's/^/mv -i /' -e 's/$/.old/' mv -i file1 file1.old mv -i file2 file2.old mv -i file3 file3.old
For moving the files, use:
You have to use the absolute path, not a relative path.Code:[~]$ls -1d /home/me/test/* | tee - | sort | xargs --max-args=2 | sed -e 's/ \/.*\// \/abc\/def\/ghi\//' -e 's/^/mv -i /' mv -i /home/me/test/file1 /abc/def/ghi/file1 mv -i /home/me/test/file2 /abc/def/ghi/file2 mv -i /home/me/test/file3 /abc/def/ghi/file3
- 02-08-2011 #5Just Joined!
- Join Date
- Feb 2011
- Posts
- 2
Already the idea of mnemo made me think: Why did I not think of that myself?
But the ideas of Kloschüssel and Lahntaler deserve some more attention than I can give it now.
But... thanks all! Here I found (possible) solutions to an old problem...
- 02-09-2011 #6Just Joined!
- Join Date
- Dec 2010
- Posts
- 16
If you use Ubuntu, then rename is a Perl script from the Perl Cookbook expecting different parameters than the rename used on other Linux distros. The rename used on the other distros is also available on Ubuntu with the program name rename.ul


Reply With Quote