I have to build a bash script that removes upper and lower lines from a file.
The script ask the person for a word, searches the word in the file and removes 4 upper lines, 9 lower lines and the line that contains the word.
Bellow are the commands that works:
vi -e -c 'g/word/.-4,-d' -c 'wq' fileName sed -i '/word/,+9d' fileName
The problem is that I want to ask the user for a word that I will use as a variable to do all that.
The bellow code doesn't work!
#!/bin/bash read -p "Insert the word:" word vi -e -c 'g/$word/.-4,-d' -c 'wq' fileName sed -i '/$word/,+9d' fileName
What should I do to solve it?
https://stackoverflow.com/questions/67441344/bash-remove-upper-and-lower-lines-from-file-using-variables May 08, 2021 at 04:32AM
没有评论:
发表评论