1

I have several files:

test1.log
test2.log
test3.log
test.txt

test.txt contains:

./test1.log
./test2.log
./test3.log

I want to be able to use my:

test.txt

with

xargs -a test.txt ......

to rename

 test1.log
 test2.log
 test3.log 

to .txt files:

 test1.txt
 test2.txt
 test3.txt

Is there a way of doing so with rename,sed,sub,or awk?

Kalanidhi
  • 4,902
  • 27
  • 42
CalcGuy
  • 169
  • 1
  • 1
  • 10

2 Answers2

3

I found my answer at this link:

http://www.commandlinefu.com/commands/view/8368/bulk-rename-files-with-sed-one-liner

It isn't exactly what I wanted to do, but it works:

ls *.log | sed -e 'p;s/.log/.txt/' | xargs -n2 mv
kingsfoil
  • 3,795
  • 7
  • 32
  • 56
CalcGuy
  • 169
  • 1
  • 1
  • 10
1

If your sed skills are not as strong or you want to use the base of the name multiple times in a general way, the following strips the extension and then allows just constructing the command from the file name without the extension.

ls **/*.txt | sed 's/\.txt$//' | xargs -n1 -i mv {}.txt {}.md

The **/.txt uses the bash shopt globstar to include the sub directories. If you don't have the globstar shopt enabled, you can replace "ls **/.txt" with an instance of the find command.

Obsidian
  • 3,719
  • 8
  • 17
  • 30
Dave B
  • 11
  • 1