Linked Questions

-3
votes
1answer
43 views

Script to change $HOME in path to tilde ~ [duplicate]

I tried: $ echo $HOME | sed 's/$HOME/~/g but this didn't work, perhaps because of forward slashes? Does anyone have a script to do this either or: using bash builtins using sed Thank you
3
votes
1answer
147 views

How to use variable in sed command

I am trying to delete two lines ( 7 and 8) from a .txt file. For this I am using following code:- #!/bin/sh Column="7" sed '"$Column",8d' myfile.txt > result.txt on running this script, I am ...
0
votes
1answer
35 views

How to insert comment at specific variable line number by sed command? [duplicate]

I want to comment out a line (add a # to the beginning). I used this command: sed -i '96s/^/#&/' file.txt on Linux to insert comment at line # 96. If the line number is a variable, then how can I ...
0
votes
0answers
17 views

remove pattern from string using sed and a variable [duplicate]

I want to remove a pattern from a string (using sed and pipes), but this pattern is not always the same and is defined previously on a variable. this example mimics the desired behavior toremove="...
-1
votes
1answer
24 views

Querry on using command “SED” for replacing text in bash shell [duplicate]

While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed? I wanted to replace constant 3 ...
0
votes
1answer
56 views

I am not able to update a variable through sed command

I have assigned two variables but not able to update x=$(cat /scratch/env.properties | grep ConfigPath) y=$(ConfigPath=/scratch/a/b) then sed to replace ConfigPath in env.properties sed 's/$x/$y/' ...
1
vote
1answer
142 views

Replacing string in a file with script [duplicate]

One of the ways replacing a string with sed can be done as follows: sed -i 's/old_str/new_str/' file.txt However if replace.sh is sed -i 's/$1/$2/' $3 the command ./replace.sh old_str new_str ...
0
votes
0answers
165 views

Use variable inside sed command [duplicate]

how can i use variables inside this sed command? sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile inside -e '{w $DIR/tempfile' -e 'd;}' the $DIR/tempfile isn't recognized
-2
votes
4answers
111 views

Json. How to add a sentence after :

The following is an extroct from a json file, that I have: }, { "name": "asdasd", "script": "dsad.js", "merge_logs": ture, "error_file": "/ofghfghgfh.log", "out_file": "/...
0
votes
2answers
50 views

make use of do loop for a variable specified in sed command [duplicate]

I have the following structure of data HG2 MET HG1 THR HG2 THR HG2 GLN The desire output would be HG1 MET HG1 THR HG2 THR HG1 GLN somehow I need to do the following for i in MET GLN do sed 's/...
0
votes
2answers
149 views

content from pwd and which failed with sed to be replaced [duplicate]

I have a file which has the following content: BWA='/software/bwa/bwa-0.7.12/bwa' SAMTOOLS='/software/samtools/samtools-1.3.1/samtools' The above tools are on my computer: which bwa => /work/...
2
votes
2answers
309 views

Using sed with an integer variable [duplicate]

I want to sed using a variable. For example, sed -n '1,10p' file. So, instead of 10, I want to use $k where k is an integer.
0
votes
0answers
285 views

Sed is not replacing with the value of a variable [duplicate]

I'm using sed to modify a file. In simple terms, my modifier looks as so sed -e '11s/$/ $LinuxUsername/' This is suppose to add in their linux username at the end of line 11, however, it is instead ...
0
votes
1answer
477 views

How to pass variable in pattern while using sed command?

I have file abc.sh search_dir='dummy' filename='numbers.txt' for entry in "$search_dir"/* do while read p; do sed -i '' "/$p/d" $entry done < $filename done Trying to delete a line ...
2
votes
2answers
2k views

how to extract just a specific part of a file name in bash [duplicate]

I have the following list of files: lab-1:/tmp/tmp.NMFaDO# ls webserver.123.net.1970-01-01.csv ...

15 30 50 per page