This question already has answers here:
How to insert strings containing slashes with sed? [duplicate]
(11 answers)
Closed 6 years ago.
I have a string like below
/home/adcde
to be replaced with efgh
so the same adcde is used some where else in the script which I don't want to replace.
so If I am replacing with the below command
sed 's/adcde/efgh/g' - it replaces the all of it
so instead I want to replace the adcde that starts with a /
sed 's/"/adcde"/efgh/g'
but it does not seem to work
any help would be appreciate?
sed 's:/adcde:/efgh:g'- solved the issue
Thanks to Benjamin for pointing it out
Related
This question already has answers here:
What is the best regular expression to check if a string is a valid URL?
(62 answers)
Closed 3 months ago.
Suppose there is a text file test.txt. It contains text and links to resources such as https://example.com/kqodbjcuic49w95rofwjue. How can I extract only the list of these links from there? (preferably via bash, but not required)
I tried this solution:
sed 's/^.*href="\([^"]*\).*$/\1/'
But it didn't help me.
grep -o "((?:(?:http|ftp|ws)s?|sftp):\/\/?)?([^:/\s.#?]+\.[^:/\s#?]+|localhost)(:\d+)?((?:\/\w+)*\/)?([\w\-.]+[^#?\s]+)?([^#]+)?(#[\w-]*)?" test.txt
will display all URLs inside the file.
(The regex comes from BSimjoo's link)
Grep text files guide at https://www.linode.com/docs/guides/how-to-grep-for-text-in-files/
This question already has answers here:
Is it possible to use "/" in a filename?
(8 answers)
Closed 1 year ago.
I have a file that I want to rename to a date like "20/02/21", but if I do mv file.txt 20/02/21 it interprets the forward slashes as referencing sub-folders. Is there a way to do this?
No, there's no way to do it. On Unix forward slash / is used to
separate directories and cannot be used in the filename. You have to
use another delimiter - 20\02\21, 20-02-21, 20.02.21 etc.
This question already has answers here:
Create string with trailing spaces in Bash
(2 answers)
Bash LeftPad String with spaces inside variable
(1 answer)
Closed 2 years ago.
Is there a pure bash way to add trailing whitespaces with something like parameter substition in the example above I am using printf in conjunction with command substition witch is not that performant
declare -ir _CONST_VARIABLE_LENGTH='30' _CONST_SUBTRACTOR='3'
declare some_var='here is a string'
declare new_var
new_var="$(printf "%-$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))s" "$some_var")"
# what i want, but doesn't work
# ${var:0:LENGTH} only goes till actually length and won't add something if LENGTH is greater than actual var lenght
new_var="${some_var:0:$((_CONST_VARIABLE_LENGTH-_CONST_SUBTRACTOR))}"
This question already has answers here:
What's the most robust way to efficiently parse CSV using awk?
(6 answers)
Closed 4 years ago.
This post was edited and submitted for review 11 months ago and failed to reopen the post:
Original close reason(s) were not resolved
I have a file like this:
col1×col2×col3
12×"Some field with "quotes" inside it"×"Some field without quotes inside but with new lines \n"
And I would like to replace the interior double quotes with single quotes so the result will look like this:
col1×col2×col3
12×"Some field with 'quotes' inside it"×"Some field without quotes inside but with new lines \n"
I guess this can be done with sed, awk or ex but I haven't been able to figure out a clean and quick way of doing it. Real CSV files are of the order of millions of lines.
The preferred solution would be a one-liner using the aforementioned programs.
A simple workaround using sed, based on your fields separator ×, could be:
sed -E "s/([^×])\"([^×])/\1'\2/g" file
This replace each " which is preceded and followed by any characters other that ×, with '.
Note that sed not support positive lookahead, so we have to group and reinsert the patterns.
This question already has answers here:
Bash insert subnode to XML file
(2 answers)
Environment variable substitution in sed
(12 answers)
Difference between single and double quotes in Bash
(7 answers)
Closed 5 years ago.
I tried to add some string between strings.
I want to add "themev2" to
<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI></SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
so that the result is
<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>themev2</SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
I tried to use
lama="<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI></SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>"
baru="<SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>themev2</SEC_FLOATING_FEATURE_COMMON_CONFIG_CHANGEABLE_UI>
sed -i 's/$lama/$baru/g' /system/etc/floating_feature.xml;
But it does not work :(