-1

I'm a new Linux user and I'm trying to run a single command for every file in a folder (let's call it Tesi). In this folder there are 4000 files and I want to create a new column in each one and put in there the relative file name (later I will merge them all).

I've tried this command, but it doesn't work:

for i in Tesi; do sed -i "s/$/\t$f/" $f; done

Any ideas?

Dave
  • 5,108
  • 16
  • 30
  • 40
  • [Bash script to execute command on all files in a directory](https://stackoverflow.com/q/10523415/608639), [Linux command: find files and run command on them](https://superuser.com/q/566198/173513), [for loop for running a command for all files in a folder](https://unix.stackexchange.com/q/167896/56041), etc. – jww Feb 28 '19 at 19:22

1 Answers1

0

Maybe this solution would be easier:

find <path> -maxdepth 1 -type f -exec sed -i "s/\$/\t\$f/" '{}' \;

If you omit or increase -maxdepth the command will search in subfolders too.

Szczad
  • 787
  • 6
  • 12