A simple find and replace without using any regex (bash)
Hi,
I need to do an exact find and replace (I don't want to use regular expressions because the input comes from user). I want to find a line that matches the user's input text and replace it with an empty string.
For example, let's say the user enters I love "Unix" and the contents of the file where I want to do find and replace is this:
Now I want to replace the line I love "Unix" with empty string. And I want to leave the remaining lines like I said I love "Unix" and I love "Unix" a lot as is. The double-quotes are intentional.
Which Unix utility can do this? An example would be great! I searched and found that sed is something close what I am looking for, but it takes a regular expression. Because the input string is coming from the user, it's tough for me to generate a regular expression for that. Any other ways?
It removes the line completely, and doesn't even leave the newline. If you require the newline to be preserved, it's a bit harder.
It's not too tough to generate a proper regular expression, per se, but it tends to be a bit ugly.
This is untested, and intended merely as a proof of concept. I probably forgot one or two special characters which need to be backslash-escaped. (Hint: remove the final part of the pipeline to see the generated script.)
Hi !
Before trying to write a code, is there any program or code that generates all the combinations of strings that simple awk regex can match.
By "simple regex" I mean let's say without "+", "*", and with a limited number of characters (e.g. from "1" to "5").
e.g:
input:
34?5
output:... (9 Replies)
Hello all!
This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician.
Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix:
... (16 Replies)
Hi!
I'm looking for a simple script, especially a one liner script in tcsh or bash
that will emulate the find/replace in all text apps.
I want to change all uppercase caracters to Title word (in wich only the first caracter is UpperCase and the rest is lowercase)
I can use sed command, but... (2 Replies)
I am trying to grep the following line in a file using a bash shell:
(..)
admin1::14959::::::
(..)
It works with the following expression (as expected)
# cat file | grep ^*::
admin1::14959::::::
but it does not work with (not expected)
# cat /etc/shadow | grep ^+::
I assume the... (2 Replies)
Hello,
I am trying to grep my log files for ORA errors, except ORA-00001.
I have tried:
grep 'ORA*!(-00001)' *.log
but it is not working.
Any help will be much appreciated.
Thank you. (5 Replies)
I am trying to write a find and replace script with AWK and I can't seem to get it to work. I need it to find this exact string *P*: and replace the P with a T or just replcare the whole thing with *T*:.
this is what I have tried
awk 'BEGIN {gsub(/\*P*:/,"\*T*:"); print}' ${INFILE} >... (4 Replies)
Hi,
I am trying to write a script which will modify a given account's settings by searching for a line in a file and then replacing the line after it. Here is a portion of my input file:
type=friend
username=0002
secret=password
host=dynamic
dtmfmode=rfc2833
mailbox=0002
context=sip... (2 Replies)
Hi all,
I am looking to create words from a sentence which adhere to a custom search pattern from my website:
Example:
! +! / += ~
where the terms ! = not, +! = AND NOT, += - and equals and ~ = can be like....
Now here is the issue...i want to split a sentence like the one above on... (1 Reply)
here is my prob ..
i have a very large text files and i need to locate specific lines, copy them and then replace a single word in the replaced text
example
find all lines that contain '/etc', copy the line immediately below (not at the end of the file) and then replace '/etc' with '/root'... (1 Reply)
I have got a question. How to do this? I mean AND expression in regex.
List all the files in current directory that do not contain the words use AND take.
Thx.:p (15 Replies)