filename manipulation using "sed"

Dear all,

I need to manipulate some filenames (dump.1, dump.2, etc.) and feed them to another command. For this purpose I am using sed and because my last COMMAND needs to receive files one-by-one I am using xargs:

>> ls dump.* | xargs sed -n 's/expression1/expression2/' | COMMAND

The problem I have is that sed opens dump.* files and does the change on the files not filenames.

if you type:

>> echo "dump.*" |xargs sed 'expression'

the change will occur on filename, so i guessed probably this will work:

>> ls dump.* | xargs echo {} | xargs sed -n 'expression'

but it didn't. still opens dump.* files.

Any ideas?

 
for i in dump.*; do echo "Do your operation here : $i"; done
1 Like

Thanks for your response itkamaraj

do u know if there is a way to feed a pipe from two resources at the same time?

what you exactly doing with the file name ?

please explain your problem clearly. after manipulating the file, what command you are trying to run ?

for i in dump.*; do new_value=$(echo "$i" | sed 's/dump/newname/'); echo $new_value; done

well I am running a python code which needs two files as its arguments: one is the dump.* file and the other an output which is somehow associated with the dump file. for instance for dump1 there should be an out1.

Now this is feasible by the code line you wrote:

for i in dump.*;
do
new_value=$(echo "$i" | sed 's/dump/newname/')
python prog $i new_value
done

I was wondering if it is possible to do it through xargs.
I was able to feed in the original dump file but I don't know about the out file.

>> ls dump.* | xargs -I {} python prog {}