I want to remove the first line of all files in a folder if the file starts with uuid and so I have a working sed
command looking like this:
$ sed -i '' '/^uuid/d' *
which works fine and removes all lines starting with uuid.
Now I want to improve the script by only removing the first line if it starts with uuid since some of the files has multiple uuid:s and only the one on the first line should be deleted. So now I improved the command to look like this:
$ sed -i '' '1{/^uuid/d;}' *
Now this command also works but only on the first file in the folder and even if I run a simple (just remove first line) version like:
$ sed -i '' '1d' *
it still only affects the first file.
Why is this?
I'm on Mac (so the BSD version of sed as I've come to understand) and I also tried installing the gnu-sed version via Brew, $ brew install gnu-sed --with-default-names
, with no luck.
I've read sed - 25 examples to delete a line or pattern in a file, sed - 20 examples to remove / delete characters from a file and googled sed delete first line in files
UPDATE 1: As proposed in the comments by john1024 I've tested with the -s
option but not sure how to use it.
$ sed -s '1d' ./*
sed: illegal option -- s
When I check man sed
I can find the -s & --seperate
option so I must do something wrong here.
UPDATE 2: Ok, progress ... find . -iname '*.yml' -exec sed -i '' -e '1{/uuid/d;}' {} \;
does the trick but I get error message saying sed: can't read : No such file or directory
Thanks for any help or guidance!
:ola
-s
option to tell sed to considers the "files as separate rather than as a single, continuous long stream." Someone who is familiar with BSD sed will have to tell you if there is a similar option on Macs. – Jampanfind ...... |sed
orfind ... -exec sed
) . You could also tryfoldername/*
or./*
and you may get lucky. ... forums.freebsd.org/threads/50187 and also here #19591480 – Halftruthfind ./ -iname '*.yml' | sed -e '1{/^uuid/d;}'
andls *.yml | sed -e '1{/^uuid/d;}'
Both which only yields a list of the files in the directory unchanged. – Melia-i ''
is required? it works just fine for me withsed -i -e ...
– Consult-i ''
is required with BSD sed, but not with GNU sed. – Ogletree