03-15-2013
Shell Script: Sorting by column using grep/awk
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
You will write a script that will read a tab-separated file that contains the names of all 50 states & Washington DC, their populations, their land areas and their population densities, which is used to order the current list. The script will ask the user if they would like to have a new file sorted alphabetically by state name, by land area or by population. If they select by name or population, the file will output the state name, then the population, then the land area. If they select by land area, the file will output the state name, then the land area, then the population. The script will save the new file either as states_alpha.txt, states_land.txt or states_pop.txt, depending on the choice selected by the user.
2. Relevant commands, code, scripts, algorithms:
grep, awk
3. The attempts at a solution (include all code and scripts):
echo "How would you like the fifty_states.txt file to be sorted?
1 ) Alphabetically
2 ) By Land Area
3 ) By Population
Enter your choice: " choice
if $choice=1
grep '^[A-Z]' fifty_states.txt | awk '{ print $1, $2, $3 }' fifty_states.txt > states_alpha.txt
This does not work...I am not sure where to go from here.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Jackson Community College, Jackson MI, USA, M. Brinkman, CIS106
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
For e.g I have a file named "relation" which has three coloums i.e
JOHN MARY JACK
PETE ALISIA JONNY
TONY JACKIE VICTOR
If I do
grep -w 'JOHN' relation | awk '{print""$1" is husband of "$2" & father of "$3""}'
It gives out
JOHN i husband of MARY & father of JACK (which is desired... (7 Replies)
Discussion started by: nick_25
7 Replies
2. Shell Programming and Scripting
Hi,
I have a text file with data in that I wish to extract, assign to a variable and process through a loop.
Kind of the process that I am after:
1: Grep the text file for the values.
Currently using:
cat /root/test.txt | grep TESTING= | awk -F"=" '{ a = $2 } {print a}' | sort -u
... (0 Replies)
Discussion started by: Spoonless
0 Replies
3. Shell Programming and Scripting
hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this;
192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible sort... (8 Replies)
Discussion started by: sam127
8 Replies
4. Shell Programming and Scripting
Hi, I'm running via PuTTY, in a BASH shell to do my work. I'm running calculations where steps are reported like this every 100 steps:
NSTEP = 249900 TIME(PS) = 249.900 TEMP(K) = 299.94 PRESS = 21.1
Etot = -12912.5557 EKtot = 4996.8780 EPtot = -17909.4336
... (6 Replies)
Discussion started by: Oriksagtaria
6 Replies
5. Shell Programming and Scripting
Hi,
I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column.
clientname,day-of-month,max-users
-----------------------------------
client1,20120610,5
client2,20120610,2
client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I have the following list:
42A
42AA
42B
42BB
42AAA
42BBB
49A
49AA
49B
49AAA
49BB
I need it to be sorted as following:
42A
42B (2 Replies)
Discussion started by: sairamtejaswi
2 Replies
7. Shell Programming and Scripting
I have a question that I am at a loss to solve. I have 3 column tab-separated data, such as:
abs nmod+n+n-commitment-n 349.200023
abs nmod+n+n-a-commitment-n 333.306429
abs into+ns-j+vn-pass-rb-divide-v 295.57316
abs nmod+n+ns-commitment-n 182.085018
abs nmod+n+n-pledge-n ... (2 Replies)
Discussion started by: owwow14
2 Replies
8. Shell Programming and Scripting
Hi have a large spreadsheet which has 4 columns
APM00111803814 server_2 96085 Corp IT Desktop and Apps
APM00111803814 server_2 96085 Corp IT Desktop and Apps
APM00111803814 server_2 96034 Storage Mgmt Team
APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies
9. Shell Programming and Scripting
Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2
Scenario 1
i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies
10. Shell Programming and Scripting
Example:
I have files in below format
file 1:
zxc,133,joe@example.com
cst,222,xyz@example1.com
File 2 Contains:
hxd
hcd
jws
zxc
cst
File 1 has 50000 lines and file 2 has around 30000 lines :
Expected Output has to be :
hxd
hcd
jws (5 Replies)
Discussion started by: TestPractice
5 Replies
LEARN ABOUT DEBIAN
populations
POPULATIONS(1) populations User Manual POPULATIONS(1)
NAME
populations - population genetic software
SYNOPSIS
populations
populations [name_of_input_file] [option]
You can use populations as a command line programm (very useful for batch treatment) to infer phylogenetic trees.
DESCRIPTION
populations is a population genetic software. It computes genetic distances between populations or individuals. It builds phylogenetic
trees (NJ or UPGMA) with bootstrap values.
FEATURES
o haploids, diploids or polyploids genotypes (see input formats)
o structured populations (see input files structured populations
o No limit of populations, loci, alleles per loci (see input formats)
o Distances between individuals (15 different methods)
o Distances between populations (15 methods)
o Bootstraps on loci OR individuals
o Phylogenetic trees (individuals or populations), using Neighbor Joining or UPGMA (PHYLIP tree format)
o Allelic diversity
o Converts data files from Genepop to different formats (Genepop, Genetix, Msat, Populations...)
OPTIONS
-phylogeny ind|pop
(default) for phylogenetic trees based on individuals or populations
dist method
(default: Nei standard, Ds) you can choose among: DAS, Dm, Ds, Dc, Da, dmu2, Fst, Cp, Dr, ASD, Dsw, Dr, Dru, Drw, Drl. see distances
for details.
-construct method
(default: upgma) possibilities upgma or nj (Neighbor Joining)
-bootstrap_ind n
number to indicate the number of bootstraps to perform on individuals
-bootstrap_locus n
number to indicate the number of bootstraps to perform on loci
.RE
-output name_of_treeview_file
to indicate the name of the tree file (phylip tree format)
-level n
number , structured populations allows to choose the structuration factor (in the example: town level is 1, building level is
2...).
EXAMPLE
populations toutc2.txt -phylogeny pop -dist Dm -bootstrap_locus 10000 -output toutc2_10000_Dm.tre
Commands can be write in a .bat file (for DOS) or a script file (for UNIX)
AUTHOR
Georges Khaznadar <georgesk@ofset.org>
Wrote this manpage for the Debian system.
COPYRIGHT
Copyright (C) 2011 Georges Khaznadar
This manual page was written for the Debian system (and may be used by others).
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or (at
your option) any later version published by the Free Software Foundation.
On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.
populations 06/19/2011 POPULATIONS(1)