0

Today I spent a day trying to do the following.

Let's say I have a file of Fortran code.

I want to change everything in this file to lower case. But if a line starts with a specific character or word, this line should not be changed.

For example, the following command

sed -i -e '/^!/! s/\(.*\)/\L\1/' $filein

does what I want, it does change everything to lower case, omitting comments (lines started with "!") or

sed -i -e '/^#include/! s/\(.*\)/\L\1/' $filein

omits lines starting with "#include" word.

Question: how to combine those two commands into one?

So basically I need to add "or" under the first condition. I have tried multiply options without any luck. I guess it should be something simple.

2

You can use OR \|:

Given a file:

!FOO
BAR
BAZ
# COMMENT

Command

sed -e '/^!\|^#/!s/\(.*\)/\L\1/' $filein

Output

!FOO
bar
baz
# COMMENT
2
  • Thank you! That's exactly what I was looking for! – Mikhail Modestov Oct 19 '20 at 20:27
  • @MikhailModestov Please accept the answer if it solves your problem. That's a way of saying thanks here at Stack networks. – Quasímodo Oct 20 '20 at 11:38
0

to do

sed -i -e "$exp1" "$file"
sed -i -e "$exp2" "$file"

you can do

sed -i -e "$exp1" -e "$exp2" "$file"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.