Assign a value to a variable which has =," [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to print the line which has below value in my text file(ex: file.txt).
I have tried multiple ways but no luck. Can someone please help me the right command.
selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))"
Please note that i need to use entire above value to check in the file.

The easiest way to assign a literal (potentially containing quotes or other shell syntax) to a variable, even though it comes with a performance penalty, is to use a quoted heredoc:
content=$(cat <<'EOF'
selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))"
EOF
)
echo "Value is: <$content>"
...correctly emits as output:
Value is: <selector="((Source IN ('VPS','VPSLegacy')) OR (JMS_TIBCO_SENDER='rig'))">

Related

Adding lines to a linux file using bash script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
I want to add lines '{"index":{"_id":$number_of_id}}' to my file name ss.josn before each json object (which is a line)
cat ss.json
input example:
{"msisdn":"255742005249","subscription_date":"2021-05-26T16:41:40.467Z","optout_date":"2022-01-03T19:12:59.808Z","total_charged_amount":1300}
{"msisdn":"255742009077","subscription_date":"2019-12-31T22:00:00.000Z","optout_date":"2022-01-09T14:08:00.282Z","total_charged_amount":3370}
{"msisdn":"255742009703","subscription_date":"2019-12-31T22:00:00.000Z","optout_date":"2022-01-01T12:34:02.104Z","total_charged_amount":400}
Desired output:
{"index":{"_id":1}}
{"msisdn":"255742005249","subscription_date":"2021-05-26T16:41:40.467Z","optout_date":"2022-01-03T19:12:59.808Z","total_charged_amount":1300}
{"index":{"_id":2}}
{"msisdn":"255742009077","subscription_date":"2019-12-31T22:00:00.000Z","optout_date":"2022-01-09T14:08:00.282Z","total_charged_amount":3370}
{"index":{"_id":3}}
{"msisdn":"255742009703","subscription_date":"2019-12-31T22:00:00.000Z","optout_date":"2022-01-01T12:34:02.104Z","total_charged_amount":400}
If you can ensure that each line is a json struct and you don't have multiline case, a script like this should do the job:
#!/bin/bash
_id=0
while read -r line; do
echo "{"index":{"_id":$_id}}" >> result.json
echo $line >> result.json
_id=$((_id+1))
done < ss.json
Maybe not the most elegant option, but you will have a result.json file with your desired output.

How to offset carriage in $write function in verilog [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I would like to print using a built-in $write() function in verilog vcs on the same line twice, where the second write starts at a specified character position beginning from the column 0. Is it even possible? The pseudo-code would be something like:
$write("Hello world"); // Assuming printed from a new line
$write("Test",10); // Starts printing on the same line at 10th position from the beginning
The output console would look like:
Hello worlTest
You need to know the proper ASCII escape sequences for the terminal the output is going to. And not all terminal windows support the same codes or this feature at all. For example see the Move Cursor commands for the vt-100.
Other than that, you can manipulate a string before printing it.

Replace URL in markdown files in python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have big markdown file. Is there any way to change /foo in my url by /bla. That is, I want to replace
[text](/foo/some-long-url/a.html)
for
[text](/bla/some-long-url/a.html)
(all ocurrences).
I know I could compile markdown file to html and use html parsers (like BeautifulSoup) to do that. But I want to do that, on the source file.
Prefered python or shell solutions.
I mean you can always replace "/foo" to "/bla" directly in the source using sed?
sed 's/\/foo/\/bla/' source.md >> destination.md
If it catches anything unwanted, you can just tweak the regular expression a bit to be more specific.

Temprarly change $PATH only for the script run [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I hope that you can help me with the following problem: I want to implement a script that requires that $PATH variables has missing . value changes in it.
The point of the script is to find requested files and copy them to parent directory. I can do this using -execdir, but the problem is that . is defined in the $PATH.
Can you please tell me how can I provide a temporary replacement for the $PATH variable that can be valid only for the script execution.
Thanks
The shell allows you to set environment variables of an executable by passing them to the invocation. Like this:
PATH="/foo/bar" program

Error in shell script and how to write to a file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a shell script that is extracting the data from a command:
I have tried running the script in both the vi and vim editor. But everything in vain.
Please help me out. And how write the output of this in a file.
It may be noted that this is just a starting point so the script will produce multiple files so
I cannot write:
Script_name > filename
I think this question is fine now, the input file is good enough after edit, I can fully understand what you ask for now.
With awk, you need learn to use 2-d array, it will simplify the code.
awk 'BEGIN{print "Instance id Name Owner Cost.centre"}
/TAG/{split($0,a,FS);a[4]=tolower(a[4]);$1=$2=$3=$4="";b[a[3],a[4]]=$0;c[a[3]]}
END{for (i in c) printf "%-18s%-26s%-14s%-20s\n",i,b[i,"name"],b[i,"owner"],b[i,"cost.center"]}' file
Instance id Name Owner Cost.centre
i-e1cfc499 Memcached
i-7f4b9300 Test_LB01_Sachin
i-c4260db8 Rishi_Win_SAML Rishi Pandey
i-fb5ca283 CLIQR-DO NOT TOUCH mataa 1234

Resources