Deleting words and sorting


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting words and sorting
# 1  
Old 08-09-2011
Deleting words and sorting

I have a file that looks some like this:
Quote:
##################################### topd Tree1 - Tree5 #######################################
* Percentage of taxa in common: 100.0%
* Nodal Distance (Pruned/Unpruned): 2.077448 / 2.077448
* Nodal Distance random (Pruned/Unpruned): ( 5.097028 +/- 0.358701 ) / ( 5.097028 +/- 0.358701 )

##################################### topd Tree1 - Tree3 #######################################
* Percentage of taxa in common: 100.0%
* Nodal Distance (Pruned/Unpruned): 1.768821 / 1.768821
* Nodal Distance random (Pruned/Unpruned): ( 5.067970 +/- 0.367315 ) / ( 5.067970 +/- 0.367315 )

##################################### topd Tree1 - Tree2 #######################################
* Percentage of taxa in common: 100.0%
* Nodal Distance (Pruned/Unpruned): 1.962142 / 1.962142
* Nodal Distance random (Pruned/Unpruned): ( 5.148824 +/- 0.367955 ) / ( 5.148824 +/- 0.367955 )

##################################### topd Tree1 - Tree127 #######################################
* Percentage of taxa in common: 100.0%
* Nodal Distance (Pruned/Unpruned): 1.470470 / 1.470470
* Nodal Distance random (Pruned/Unpruned): ( 5.058969 +/- 0.347412 ) / ( 5.058969 +/- 0.347412 )

##################################### topd Tree1 - Tree88 #######################################
* Percentage of taxa in common: 100.0%
* Nodal Distance (Pruned/Unpruned): 1.529534 / 1.529534
* Nodal Distance random (Pruned/Unpruned): ( 5.073246 +/- 0.355342 ) / ( 5.073246 +/- 0.355342 )
I need to delete most of the information and sort the rest in such way that I get the following output file
Quote:
Tree2: 1.962142
Tree3: 1.768821
Tree5: 2.077448
Tree88: 1.529534
Tree127: 1.470470
Any help will be greatly appreciated

Last edited by Xterra; 08-09-2011 at 12:57 PM..
# 2  
Old 08-09-2011
With GNU sed and sort:
Code:
sed -n '
/Tree/ { s/^.*\(Tree[0-9]\+\).*$/\1: /; h}
/Distance (/ { s|^.*/ \([0-9.]\+\)|\1|; x; G; s/\n//p }
' INPUTFILE | sort -V -k1,1   
Tree2: 1.962142
Tree3: 1.768821
Tree5: 2.077448
Tree88: 1.529534
Tree127: 1.470470

For "pruned" data and for not GNU sed and sort:
Code:
sed -n '
/Tree/{
s/^.*\(Tree\)\([0-9]\+\).*$/\1 \2:/
h
}
/Distance (/{
s|^.*: \([0-9.]\+\) / [0-9.]\+$|\1|
x
G
s/\n//p
}
' INPUTFILE | sort -n -k2,2 | sed 's/ //'


Last edited by yazu; 08-09-2011 at 01:28 PM..
This User Gave Thanks to yazu For This Post:
# 3  
Old 08-09-2011
Problem with the last section

Everything is fine but this part is giving me an error:
Code:
sort -V -k1,1

Quote:
sort: invalid option -- v
I do not see the '-v' option under sed. Am I missing something here?

---------- Post updated at 12:41 PM ---------- Previous update was at 12:39 PM ----------

That took care of it!
Code:
sed -n '
/Tree/{
s/^.*\(Tree\)\([0-9]\+\).*$/\1 \2:/
h
}
/Distance (/{
s|^.*: \([0-9.]\+\) / [0-9.]\+$|\1|
x
G
s/\n//p
}
' INPUTFILE | sort -n -k2,2 | sed 's/ //'

# 4  
Old 08-09-2011
This is option for GNU sort - version sort. I've given another variant.
This User Gave Thanks to yazu For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting a list of words from a text file

Hello, I have a list of words separated by spaces I am trying to delete from a text file, and I could not figure out what is the best way to do this. what I tried (does not work) : delete="password key number verify" arr=($delete) for i in arr { sed "s/\<${arr}\>]*//g" in.txt } >... (5 Replies)
Discussion started by: Hawk4520
5 Replies

2. UNIX for Dummies Questions & Answers

Deleting words between every appearance of two words

Hi there, newbie there. I've been browsing the forums hoping to find a solution that answers a problem similar to what I need, but haven't had much luck. Any help would be greatly appreciated. Thanks! I need to delete a bunch of text between every appearance of two words in a really large file... (3 Replies)
Discussion started by: lendl
3 Replies

3. Shell Programming and Scripting

Sorting a list of words one per line by their ending

Hello, My OS is Windows and therefore DOS. Hence I have no access to Unix tools. I am trying to sort a file in Urdu by the character by which it ends. Each word is on a separate line. As input, an example in English would help: fruit banana apple pear house I need the sort to be on the... (5 Replies)
Discussion started by: gimley
5 Replies

4. UNIX for Dummies Questions & Answers

Sorting words based on length

i need to write a bash script that recive a list of varuables kaka pele ronaldo beckham zidane messi rivaldo gerrard platini i need the program to print the longest word of the list. word in the output appears on a separate line and word order in the output is in the order Llachsicografi costs.... (1 Reply)
Discussion started by: yairpg
1 Replies

5. UNIX for Dummies Questions & Answers

deleting words in list with more than 2 identical adjacent characters

Morning Guys & Gals, I am trying to figure out a way to remove lines from a file that have more than 2 identical characters in sequence.. So if for instance the list would look like ; the output would be ; I can't seem to get my head around perl (among many other... (7 Replies)
Discussion started by: TAPE
7 Replies

6. Shell Programming and Scripting

Need some help deleting words from a line which are not my "Keyword"

Hi, i'm currently new to scripting and need some help with my problem, so i'll jump right to it. I have a file containing text, the file is pretty big so for the sake of this i'll just say this is the text: John id number is abc34938 Grahams id number is pending id number abc64334 is Bob's ... (14 Replies)
Discussion started by: linuxkid
14 Replies

7. Shell Programming and Scripting

Deleting words between tags

Hi !!! I need to write a script(ksh) that deletes any character outside <start> tag and </start> from a file. For eg: $cat file.txt <start> ad bd </start> as</start> <start> d e f mb<start>mu g h i (7 Replies)
Discussion started by: PRKS
7 Replies

8. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

9. UNIX for Dummies Questions & Answers

need help sorting/deleting non-unique things

I don't really know much about UNIX commands, so if someone could help me understand how to do this, I'd really appreciate it. I have a text file with data that looks like this (filename: numbers.txt): 1 1 1 1 1 1 1 1 1 2 1 1_2 2_1 1 1 1 1 1 1 1 1 2 1 2 1_2 2_1 1 1 1 1 1 1 1 1 2 1 2 1_2 2_1... (12 Replies)
Discussion started by: zac100
12 Replies

10. Shell Programming and Scripting

deleting symbols and characters between two words

Hi Please tell me how could i delete symbols, whitespaces, characters, words everything between two words in a line. Let my file is aaa BB ccc ddd eee FF kkk xxx 123456 BB 44^& iop FF 999 xxx uuu rrr BB hhh nnn FF 000 I want to delete everything comes in between BB and FF( deletion... (3 Replies)
Discussion started by: rish_max
3 Replies
Login or Register to Ask a Question