Tags down


How to use the value in a file as input for a calculation in awk - in bash?

By : Mariusz
Date : August 02 2020, 09:00 AM
will help you I'm trying to calculate if the count for each row is more than a certain value, 30% of the total counts. , You can filter on a column based on a value e.g
code :
$ awk '$3>300' data.csv
SampleID    ASV    Count
1000A   ASV_135     434
1000A   ASV_16      361

Share : facebook icon twitter icon

Bash script putting input without input redirection for a c++ file

By : steve dean
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This is what I have" , But what you actually want is:
code :
./make.o output$ctr.txt >out$ctr.txt
int main(int argc, char *argv[])
    if (argc < 2) {
        // argv[0] usually contains the program name
        std::cerr << "missing argument\n"
                  << "Syntax: " << argv[0] << " input-file\n";
        return -1;

    char *input = argv[1]; // = "output$ctr.txt"
    // ...
./make.o  >out$ctr.txt <output$ctr.txt

How to load calculation input from text file with Python?

By : Niki Gotcher
Date : March 29 2020, 07:55 AM
help you fix your problem If we convert this to a dictionary we will have a lot of flexibility with what we want to do with the information. This can be done with a little effort. We can use the first line to create our keys then we can zip those keys with each other line, then create a list of tuples by zipping those lists. From there we can use a dictionary constructor to create our list of dictionaries. Now we just have to gather all keys from this list of dictionaries that are subjects for each item in the list, map those to ints and create an exception for when the student has scored all 0s. If not we filter out the 0's from a complete list and then calculate average. Next to get averages for each subject we can extract all the values that are connected to that subject, not taking values that are 0, same we map ints and then calculate average. I threw in some text justification for appearances, not neccessary. The process for the remaining subjects would be the same just swap out the subject.
code :
with open('text.txt') as f:
    content = [line.split() for line in f]

keys = content[0]

lst = list(zip([keys]*(len(content)-1), content[1:]))
x = [zip(i[0], i[1]) for i in lst]
z = [dict(i) for i in x]

print('Average Grades'.center(30))
for i in z:
    subs =[i['subject1'], i['subject2'], i['subject3'], i['subject4'], i['subject5']]
    subs = list(map(int, subs))
    if sum(subs) == 0:
        print('{:<10} average grade: {:>4}'.format(i['Name'], 0))
        subs = list(filter(lambda x: x >0, subs))
        avg = round(sum(subs)/len(subs), 2)
        print('{:<10} average grade: {:>4}'.format(i['Name'], avg))

sub1 = [i['subject1'] for i in z if i['subject1'] != '0']
sub1 = list(map(int, sub1))
sub1_avg = sum(sub1)/len(sub1)
print('\nAverage Grade for Subject 1: {}'.format(sub1_avg))
        Average Grades        
Jan        average grade:  5.5
Marie      average grade: 5.67
Kees       average grade:  7.5
André      average grade:  6.2
Antoinette average grade:  6.5
Jerôme     average grade:  7.0
Kamal      average grade: 7.75
Diana      average grade:    0
Petra      average grade: 6.25
Malika     average grade:  7.0
Samira     average grade:  6.8

Average Grade for Subject 1: 5.5

Bash - How to input lines in rst file after specific line number in bash script

By : dannij0913
Date : March 29 2020, 07:55 AM
I wish this helpful for you If you want to insert the output of find . -name '*.rst' with .rst suffix removed into line 11 of some file, you can:
code :
# generate the list with .rst files
# I use `printf "%f\n"` to print only the filename, ie. remove the  `./` part
# sed is used to remove the .rst
find . -name '*.rst' -printf "%f\n" | sed 's/.rst$//' > sometempfile.txt
# Insert the content of sometempfile.txt into 11nth line in the main.rst file
sed -i -e '11r sometempfile.txt' main.rst
# pick up the trash
rm sometempfile.txt

how to store a calculation from an input to memory, input repeats, first calculation from input is added to second calcu

By : user3176198
Date : March 29 2020, 07:55 AM
seems to work fine This piece of code will work. import java.util.Scanner;
public class ElectricalBillingProgram {
code :
public static void main(String[] args)
    Scanner console = new Scanner(System.in);
    Double loopFor = 0.0;
    Double w, h, kwh, t;
    for (int i = 0;; i++)
        System.out.print("\nEnter what is being asked. You might have to refer to labels on your appliances");
        System.out.print("\nWATTAGE (W): ");
        w = console.nextDouble();
        System.out.print("\nUSAGE (in HOURS): ");
        h = console.nextDouble();
        System.out.print("\nELECTRICITY RATE (kWh): ");
        kwh = console.nextDouble();

        t = (w * h) / 1000 * kwh;

        System.out.print("\nCOST: " + t);
        loopFor += t;

        System.out.print("\nWould you like to continue? YES [y] No [n]");
        String c = console.next();

        if (c.equalsIgnoreCase("n"))


how to execute bash script from python (bash file contains user input)

By : user3206040
Date : March 29 2020, 07:55 AM
seems to work fine Okay, got your problem. You have to use module subprocess and use communicate function to communicate user input to the respective function. subprocess.communicate will send user input to the sub process that has been created by subprocess modeul itself. Check this code bit below. This peace of code is passing input "Ajay" to the test.sh script. This is a logic and an attempt to show you how things be done.
In your case, create a python script on a remote machine which does sourcing the bash script and from python script, you can pass on the input to the bash script
Related Posts Related Posts :
  • Why does ${##parameter} always return 0?
  • How to embed and run a multi-line perl script stored in a bash variable in a bash script (without immediately running pe
  • Bash Multiple conditions in while loop
  • Bash test variable and program exit in same statement
  • How to read multiple integers on same line in bash?
  • What cd expect from me in this case?
  • Remove color and redirect ouptut of a bash script from within
  • Calculate all possible sum combinations in a given array of space delimited numbers using BASH
  • How to output the result of a chain of commands for a given input with bash
  • text-file manipulation in bash
  • extract characters from second occurrence of dash in a string
  • Failing to run external Bash program — /usr/bin/bash: bad interpreter: No such file or directory
  • Parsing data from function in POSIX
  • exclude directories with the same name ending
  • Piping into grep using cat returns error: no such file or directory
  • Why echo of combined variables in for loop doesn't work?
  • Bash: how to look for the next positional parameter in "case" code without hard-coding its value?
  • Can I pipe the pathname expansion to a command?
  • How to sort by numbers that are part of a filename in bash?
  • Removing character(s) from multiple file names
  • awk print "matched" after successful match
  • Best way to find value of a Bash variable in another file without "source"?
  • GNU parallel - how to handle column separator without spaces or new line?
  • awk: remove multiple tabs between each fields and output a line where each field is separated by a single tab
  • bash: how loop through array of dir paths and remove their certain parts
  • Sort and count number of occurrence of part of a filename with "ls"
  • The cat, the echo, and the process substitution
  • cannot use filter on grep to search for all path including a string
  • bash function fails with set -e
  • Watch and wc not yielding any results
  • Compare two version of zip file and find which file has been modified within that zip
  • Convert eGrep to Grep
  • Stuck with bash script
  • How to merge two GZIP files, while removing the first row from the second file?
  • Remove duplicate lines in braces
  • Functions containing bash variables inserted into perl strings through variables passed through the intiiation of a func
  • Use pipe ("|") as first symbol in bash or zsh command
  • List full lines based on single field much faster than grep
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org