Skip to content
Advertisement

Tag: bash

Replace line with double quotes

I want to replace a line with double quotes on OpenBox startup, like: with I use this command, but it does not work: It gives me this error: Answer The ampersand in the replacement string recalls the pattern in the search string. So you can just do this: Also, you can use single quotes on the outside, and double quotes

Bash offer numberd results for selection to user

my script takes in a site name from the user. Its then allows the user to checkout, edit, and commit changes to the file, via the script. However, some sites have two to six files. So the script lists them as follows You have more than one Cambridge file. Please pick from the following: cambridge1 cambridge2 cambridge3 user enters the

Linux – rename all files by replacing last hyphen with ‘##’

Please anyone. How do I in Linux rename a bunch of files like: abc-def-0001.xxx acb-def-0002.xxx to: abc-def##0001.xxx … I have tried several suggestions from SO like: rename ‘s/(.*)-/$1##/’ *.xxx But didn’t worked as expected in my environment. Answer So I ended up using: for i in *; do mv “$i” “`echo $i | sed “s/(.*)-/1##/”`”; done I think my version

How do I read the whole command line?

Command $ ls -l | ./main.out The output will show My question is, how do I make my program to read the command before that, ls -l Answer Command line parameters are passed as arguments when calling the program. And your program will read the entire command line arguments. But What you are doing ($ ls -l | ./main.out) is

formatting the output with sed command

I need your help… I got this kind of text: and the output I need is (first and second column and socialSecurityNumber OR tng-customer-id): So the question is … is it possible to solve this issue with sed command? I need the OR option here. If I try to do it separately, firstly, find the socialSecurityNumber, I get this: secondly,

Bash ssh for loop – env variable issue

When using a bash for loop and ssh’ing to multiple machines the hostname variable is not updated to be the name of the machine I’ve ssh’d into. What am I missing here? “A”, “B”, “C” are replaced with names of actual machines and the speech marks removed in the actual execution. In the example above $node is correctly outputted but

Search and replace file content using shell script

I want to search and replace specific value in a file, here is the content of the file I want to replace DocumentRoot /var/www/html with DocumentRoot /var/www/html/centos I tried the following This is not working, can someone point me to the right direction. Thanks Answer The line you are trying to replace is: It contains double-quotes. The sed command does

Advertisement