Skip to main content

All Questions

Tagged with
1 vote
3 answers
79 views

sed: update 2 similar variables in a file but keep the upper and lowercase

I have 2 variables in a file like below that I need to assign a new value inserted by one user input: read -p "Enter CName Name : " CName sid=C02SBX SID=C02SBX When I run the following ...
Ali's user avatar
  • 123
0 votes
2 answers
569 views

Use SED to replace part of a current variable with user input variable

I'm trying to replace only part of the existing variable with a new user input variable as below: #Current Variable: gdbName=Test.MY.DOMAIN.COM <--I need to replace the "Test" (This can ...
Ali's user avatar
  • 123
0 votes
1 answer
98 views

Add function in variables in while loop

I am writing script to run a software. I am trying to add function in while loops to trim text in variable, so that it can be applied as variable in other part of the command. But what should be the ...
web's user avatar
  • 193
0 votes
3 answers
837 views

Trying to read XML attributes from multiple files and replacing them with a number 1.25 times greater than they were before

I am trying to write a bash script or something similar, that I can use to modify all occurrences in a bunch of xml files with one click. I have 24 xml files, each containing a few dozen lines and ...
xOverload86x's user avatar
1 vote
2 answers
2k views

Print lines using line-numbers stored in shell variable, using sed

I have a tab file from, which I am extracting the column containing the row numbers I need to extract lines from another file. I got the line numbers with cut -f and I stored them into a variable list....
Gigiux's user avatar
  • 547
2 votes
2 answers
2k views

sed with external script file - How to apply shell variables?

Directly on the command line, this works: $sed "s/a/X/;s/X/&a&/" file and so does using shell variables: $varin=a ; varout=X ; sed "s/$varin/$varout/;s/$varout/&$varin&/...
FelixJN's user avatar
  • 13.9k
5 votes
1 answer
3k views

How to append text stored in a shell variable in the beginning of the file by using sed?

I found interesting discussion here and tried the solution given with sed How to insert a text at the beginning of a file? https://stackoverflow.com/a/9533736/13353532 It works with normal text, but ...
Wolf's user avatar
  • 1,731
1 vote
0 answers
194 views

Two lines are removed with sed instead of one, why? [duplicate]

I am attempting to remove lines from this text file (foo.txt): cat mouse animals: 2 I want to remove the two lines from the end: ‎ animals: 2 So I end up with this: cat mouse However, when using ...
leetbacoon's user avatar
0 votes
1 answer
411 views

When using variable in sed it replaces entire line, instead of just the matching string

I'm new to bash and I've been trying to understand other posts that's similar, but I'm just not sure if they do the thing I need. When I don't use variables and just put in what I want to search for ...
brauown's user avatar
1 vote
1 answer
251 views

Text processing with sed on a variable in bash not giving expected (modified) output?

We are using some outdated encoded script which does not to be allowed to be modified. Therefor I though of a solution to modify the input automatically by using sed. This didn't work and after ...
Joanne's user avatar
  • 135
2 votes
2 answers
173 views

Linux Bash: Variable to another variable [duplicate]

i have this: echo $MSG | sed -e $'s/;/\\\n/g' I want to put the result of that sed in a new variable called $MSG2 Something like: $MSG2=echo $MSG|sed -e $'s/;/\\\n/g' How can i do it? Thank you!
Kyle Smith's user avatar
3 votes
1 answer
1k views

Bash string range and replace

To print part of the string, replace , with . I use command: echo "${q:16:6}" | sed 's/,/./' Is it possible to use something like: echo "${q:16:6/,/.}" because it does not work?
pbies's user avatar
  • 494
1 vote
2 answers
2k views

elif condition in an if statement

I have this variables start=$1; end=$2; sn=${#start} en=${#end} and this if : if ( [ $# -eq 2 ] ) then elif ( [ $sn -ne 3 ] && [ -n "$(printf '%s\n' "$start" | sed 's/[0-9]//g') " ] ); then ...
bboy's user avatar
  • 47
0 votes
1 answer
7k views

Replace values in a variable and retain new lines in BASH

This BASH script works as expected. I have a variable ($foo) that contains lines of data, I tell bash to separate at new lines, and I loop through the variable. #!/bin/bash foo=" Original Line1 ...
JeremyCanfield's user avatar
2 votes
1 answer
1k views

How can one prepend text to each line of a multi-line variable?

I print all the variables with there values echo "$val" mapreduce.map.memory.mb,3584 mapreduce.map.java.opts,-Xmx2560m mapreduce.reduce.memory.mb,3584 mapreduce.reduce.java.opts,-Xmx2560m ...
yael's user avatar
  • 13.9k

15 30 50 per page