Skip to content

Tag: bash

Can we replace one variable with multiple variables using sed

I have a config file where i need to replace the entire line with new values. It can be either a word or a URL. I am trying to write a script to replace only this particular parameter with new values. I have tried using grep to extract the line using the parameter and divided the values separately and saved

Create filename based on file output in shell

I’m looking to create files with names based on the command output of the previous command i.e. if i run So that the output of the amount of files of that type is the filename of the created file. Answer Here’s a solution that renames the file after it has been created: What is happening in this o…

Bash loop only read the last line

I have problems trying to extract data behind colons in multiple lines using while loop and awk. This is my data structure: What I want to get is the BioSample ID, which is like SAMD00019077. Scripts I tried: while read line ; do echo $line | awk -F’:’ ‘{print $3}’ > 1.tmp2 ; done &…

Problem inserting on first match only using GNU sed

4 on my linux machine (I checked w/ sed –version). Currently, I have a myfile.txt with the following content: I know in GNU sed, I can append after the first occurrence of a match if I prepend the sed command with 0,. So, if I want to insert goodbye after the first occurrence of —, I can do that: …

“Cache” credentials on a bash script

I have created a bash script to run a few js scripts into MongoDB. Basically, what I am doing is, running the bash script and passing a parameter in this case called version, example: That will go and execute all scripts for the version 1.0. Now, it is possible that MongoDB requires authentication user/pass, …

How to include path inside bashrc in linux for envirnment

Im testing my code for automation of the installation of a software In bashrc file below: Here im trying to add $SCALA_HOME/bin to PATH. this is the required output: the above code worked to append SCALA_HOME above path but for appending in the same line im not able to do please help me get the correct sed co…

Conditional append of strings on fields in a csv file

I am trying to convert a csv file like below with bash scripts. Headers and structures are always the same. Source csv file: Conditional values (will change depending on the requirements) Now I am trying to get the following result without the first row and values are now separated by spaces if each header ma…