So i am needing to write a one-line awk command to calculate the percentage of a unique word that shows up in field 2 of my comma delimited file using linux terminal. I wanting to calculate the percent that the unique word "10_GOP" shows up in field 2.
Here i've provided the awk command for your requirement.
*** HERE IS THE COMMAND ***
awk -F "[,]" '{ if($2 == "10_GOP") count = count+1} END {print(count/NR)*100}' <file_name>
The if condition sees if the 2nd field is "10_GOP" and will increment the count variable. At the end we divide the count variable by total number of lines and multiply it by 100 to get the percentage.
Make sure that the file is comma seperated.
For any queries please do comment.
So i am needing to write a one-line awk command to calculate the percentage of a...
Write an awk command that will calculate the sum of all digits in a specified file. So the number 251 would be 2+5+1, it would do this for all numbers found in a file providing just sum as the output.
I need to write a linux command to calculate the number of times an item shows up in column 1 within a certain date range, 1/1/2017 0:00 to 12/31/2017 24:00. So how many times it shows up in column one withing the year 2017. the dates given are the formatted version of the CSV file.
I am writing a C program that takes either command line arguments or has a file passed to it using < on the command line. My question is how do I check to see if there is a file passed using <. I think I need a way to check stdin to see if there is any data present. Thanks
(COMMAND LINE) I have a file, abc.csv and I am interested in a command line solution (not something like C coding) for the following: In which zip code was the highest number of narcotic/drug offenses. ZIP_CODE and ABC_CODE are the relevant headings but there are many headings and many records within the file. Within ABC_CODE, 35A and 35B are narcotic and drug offenses. So, I want to find out which zip code has the highest number of narcotic/drug offenses, which...
I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!
Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command not found line 10: syntax error near unexpected token `then' line 10: `then' ------------------------------- #!/bin/bash if [ $# != 1 ] then echo "Usage: myScript.sh " exit 1 fi if [ -f $1 ] then awk ' BEGIN...
I am a college student taking an INTRODUCTORY linux shell programming course and need some help with writing a for statement. How would I write a for statement to process all the arguments at the command line and indicate if the argument contains the name of a student in my class. The names of the students are in the file cis132students. I realize you do not have the file but if you could write it I could see if it...
Write a program Adder.java that calculates and prints the sum of command line parameters, so if you make the command line parameters be 2 5 22 then the program prints 29. Write a program ShowFiles.java that assumes the command line parameters are each a text file name directly readable by the program. For each file named, print out the three heading lines in the format shown, and then each line of the file contents. If file q.txt contains What is...
Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...
a) Write a one-line sed command that will replace all multiple spaces in a file called names.txt (this is an arbitrary file that you may create yourself) by only one space. b) Consider the following file called system.txt: 1 2 3 4 5 6 7 8 9 He 11 Hg Ts H 15 Be 17 Mc Li 20 Write a one-line sed command that replaces the second number in every line with the string “system”, without the quotes. For example,...