Tmux is a terminal multiple for Unix OS. It provides multiple terminal sessions to its users. It is used when we are using cloud-based services (like Azure, AWS) for the creation of separate terminals for different remote users.While working with web services, one needs to create an EC2 instance on the webserver provided by the company to work on it by creating a session.Now, let’s see the steps of working on a UNIX (Ubuntu) webserver.Step 1 − Write/copy the IP address of your AWS console and download the key file from the console. You will get these from your vendor ... Read More
In this program, we are given a file name text.txt. Our task is to print a particular line from the file.For this there are multiple methods in bash script, they are awk, sed, head.Syntax$> awk ‘{if(NR==LINE_NUMBER) print $0}’ filename $> sed -n LINE_NUMBERp filename $head -n LineNumber filename | tail - n + LINE_NUMBERCode to print a specific line in bash programming from file text.txt.Using awk$> awk ‘{if(NR==5) print $0}’ text.txtUsing sed$>sed -n 5p text.txtUsing head$head -n 5 filename | tail - n + 5
Here, we will write a C program that will display the contents of a file page by page as displayed in Linux using the more command.This program will show a specific number of lines on the screen first and then wait for the user to hit enter to move to the next page i.e. next set of n lines.For displaying the content of the file like this we will open the file and print its contents. And maintain a counter for new lines in the file. When this counter reaches n, we will read a key pressed by the user ... Read More
Here, we will write some c programs that won’t compile in c++. Though c++ is considered as a successor of c that has all its features and has compatibility with c code there are some programs that won’t compiler or given a compilation error when compiled with c++ compiler.A list of some of the C programs that won’t compile in c++ are −Call to a function before declaration − In c++, function call before declaration gives compilation error. But this works fine in c.Example Live Demo#include int main(){ printHello(); return 0; } void printHello(){ printf("TutorialsPoint"); }OutputTutorialsPointUsing typecasted ... Read More
The best way to add an event to any element is to use the addEventListener() method.Following is the code to add an event in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result{ font-size: 20px; font-weight: 500; color: rebeccapurple; } Adding event in JavaScript CLICK HERE Click on the above button to increment the font size of above text let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { resEle.style.fontSize = "34px"; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Following is the code to decrement a date by 1 day in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result,.sample { font-size: 20px; font-weight: 500; color: rebeccapurple; } JavaScript program to decrement a date by 1 day Decrement Click on the above button to decrement the date by one day let resEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); let date = new Date(); sampleEle.innerHTML = date; document.querySelector(".Btn").addEventListener("click", () => { date.setDate(date.getDate() - 1); resEle.innerHTML = "New Date = " + date; }); OutputThe above code will produce the following output −On clicking the ‘Decrement’ button −
Following is the code for finding keys of a hash in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Find keys of a hash in JavaScript DISPLAY Click on the above button to display the hash keys let resEle = document.querySelector(".result"); let obj = { firstName: "Rohan", lastName: "Sharma", age: 22, }; document.querySelector(".Btn").addEventListener("click", () => { resEle.innerHTML += "object keys are " + Object.keys(obj); }); OutputThe above code will produce the following output −On clicking the ‘DISPLAY’ button −
Following is the code to validate decimal numbers in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Validate decimal numbers in JavaScript CHECK Click the above button to check if a valid decimal number is entered or not let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { var str = document.querySelector(".num").value; var regex = /^[-+]?[0-9]+\.[0-9]+$/; ... Read More
Following is the code to remove a child node in HTML using JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Removing a child node in HTML using JavaScript Cow Lion Tiger Buffalo CLICK HERE Click the above button to remove the first list element from the above list let resEle = document.querySelector(".result"); let animalList = document.querySelector(".animal"); document.querySelector(".Btn").addEventListener("click", () => { animalList.removeChild(animalList.childNodes[0]); animalList = animalList; }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
Following is the code to load a JavaScript file dynamically −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; } Load a JavaScript file Dynamically CLICK HERE Click the above button to load external JavaScript let resEle = document.querySelector(".result"); document.querySelector(".Btn").addEventListener("click", () => { var jsRef = document.createElement("script"); jsRef.setAttribute("src", "sample.js"); document.getElementsByTagName("head")[0].appendChild(jsRef); }); script.jsresEle.innerHTML='JavaScript has been loaded';OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −