Saturday, August 31, 2019

bash - Terminal sed into .command file



I have this script to remove the first 4 lines of every file in a folder if their extension is .txt.



I want to be able to place a file.command with this script in the same folder so I can just double click on it and execute it.




So I made a file with this:



#!/bin/bash

find . -type f -name "*.txt" -exec sed -i.bak '1,4d' {} \;


If I run the file I have all of my Mac txt files 4 lines removed :(



I thought the find . was meant to stay in the same folder ...




How do I fix it in order to have the command run ONLY in the folder the file.command is?



This code:



find . -maxdepth 1 -type f -name "*.txt" -exec sed -i.bak '1,4d' {} \;


actually works, the issue were:





  1. The created file with the command wasn't made executable for that do:



    chmod +x file.command

  2. Then run the command from the terminal with:



    ./file.command



No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...