You can use the change command to replace the entire line, and the -i flag to make the changes in-place. For example, using GNU sed: sed -i '/TEXT_TO_BE_REPLACED/c\This line is removed by the admin.'... Read More
Use the -r (or --raw-output) option to emit raw strings as output: jq -r '.name' <json.txt... Read More
If you don't want to print the matched line (or any following lines): sed -n '/The second line/q;p' inputfile This says "when you reach the line that matches the pattern quit, otherwise print each li... Read More
The key to getting this to work is to tell sed to exclude what you don't want to be output as well as specifying what you do want. string='This is a sample 123 text and some 987 numbers' echo "$strin... Read More
You can escape the space character, for example to add 2 spaces: sed -i "${line} i \ \ ${text}" $file Or you can do it in the definition of your text variable: text="\ \ hello world"... Read More
If you are using GNU sed then you need to use sed -r which forces sed to use extended regular expressions, including the wanted behavior of +. See man sed: -r, --regexp-extended use extended... Read More
If you want to interpret $replace, you should not use single quotes since they prevent variable substitution. Try: echo $LINE | sed -e "s/12345678/\"${replace}\"/g" assuming you want the quotes put i... Read More
Use Awk. awk '{ print length }' abc.txt... Read More
If you wanted to remove a certain NUMBER of path components, you should use cut with -d'/'. For example, if path=/home/dude/some/deepish/dir: To remove the first two components: # (Add 2 to the numbe... Read More
find /home/www \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g' -print0 tells find to print each of the results separated by... Read More