1

I want to search a file with name file.txt in a directory and replace entire line in those files with a string aprun by another line vasprun = "mpirun -np 64 vasp" How can I do this with awk or sed or any other bash utility?

2 Answers 2

4

With GNU bash and GNU sed:

shopt -s globstar sed -i 's/.*aprun.*/vasprun = "mpirun -np 64 vasp"/' -- **/file.txt 

From man bash:

globstar: If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.

Sign up to request clarification or add additional context in comments.

Comments

1

You can also find the file using the find command and pipe the output to sed command

find . -name file.txt | sed -i 's/.*aprun.*/vasprun = "mpirun -np 64 vasp"/g'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.