How to sort lines by strings between ()?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to sort lines by strings between ()?
# 1  
Old 12-08-2010
Question How to sort lines by strings between ()?

Hello,everyone. I am learning some Info commands.I put all commands and their explanations in a file.

This is a part of it:

Code:
ESC PgUp (scroll-other-window-backward)Scroll the other window backward
ESC Right (forward-word)  Move forward a word
ESC r (move-to-window-line)
ESC TAB (move-to-prev-xref)
ESC Up (prev-line)   Move up to the previous line
ESC v (scroll-backward-page-only)

Now I want to sort these lines by the alphabetical order of the commands' names. The commands' names are between the parentheses and not in the same colomn of lines.

Thanks.

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 12-08-2010 at 05:59 PM.. Reason: code tags, please!
# 2  
Old 12-08-2010
Code:
nawk -F '[()]' '{print $2,$0}' OFS='|' myFile | sort -t '|' -k1,1 | cut -d '|' -f2-

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 12-08-2010
Hi,

What about this?
Code:
$ cat infile
ESC PgUp (scroll-other-window-backward)Scroll the other window backward
ESC Right (forward-word)  Move forward a word
ESC r (move-to-window-line)
ESC TAB (move-to-prev-xref)
ESC Up (prev-line)   Move up to the previous line
ESC v (scroll-backward-page-only)
$ sort -k3,3 infile
ESC Right (forward-word)  Move forward a word
ESC TAB (move-to-prev-xref)
ESC r (move-to-window-line)
ESC Up (prev-line)   Move up to the previous line
ESC v (scroll-backward-page-only)
ESC PgUp (scroll-other-window-backward)Scroll the other window backward

Regards,
Birei
# 4  
Old 12-08-2010
the first works perfectly Thank both of you .
I don't have nawk, but awk can also do that.Smilie

Last edited by vic005; 12-08-2010 at 06:18 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Strange results from 'strings | sort'

Using the 'strings' command and piping the result to 'sort' is producing strange results. I get block of lines that begin with asterisks, then a block that begins with some text, then more lines that begin with asterisks. The actual content is correct - lines beginning with asterisks is the... (5 Replies)
Discussion started by: edstevens
5 Replies

2. Shell Programming and Scripting

Sort strings containing numbers

How can I sort this, first by 2nd field then by 1st field. tried sort -b -k 2,2 Input: AS11 AB1 BD34 AB10 AF12 AC2 A345 AB10 R134 AB2 456 AC10 TTT2 BD12 desired output: AS11 AB1 R134 AB2 A345 AB10 BD34 AB10 AF12 AC2 456 AC10 TTT2 BD12 (2 Replies)
Discussion started by: aydj
2 Replies

3. Shell Programming and Scripting

Sort strings with numbers

I want to sort my data first by the 2nd field then by the first field. I can't use sort -V because I don't have gnu sort and cannot install one. How do I go about this? Input: G456 KT1 34 K234 KT10 45 L2 KT2 26 H5 LAF2 28 F3 LAF2 36 Output: G456 KT1 34 L2 KT2 26 K234 KT10 45 F3... (14 Replies)
Discussion started by: aydj
14 Replies

4. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

5. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

6. Programming

Sort ascending n strings in C

Hy guys. My English is not so good, sorry for any mistakes. I'm a bigginer in C, and I have a problem. I want to sort ascending n strings, but I can't read the strings. Here is what I've done so far: //sort ascending n strings #include <stdio.h> int main() { int n,i,j; char a; ... (8 Replies)
Discussion started by: 1/0
8 Replies

7. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

8. Shell Programming and Scripting

how to sort strings by length?

I'm trying to find the longest word in /usr/share/dict/words The first thing I can think of is to sort the content by length then it would be easy to find out, but then i realize theres no option of sort to sort by length. Could you guys please give me some help?:confused: (7 Replies)
Discussion started by: rockbike
7 Replies

9. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies

10. Shell Programming and Scripting

sort() array of strings in perl

I have a perl script with an array of clients. @arr = ("The ABC Corp", "AA Corp.", "BB Corp"); If I run @a = sort (@arr); I will get @a = ("AA Corp", "BB Corp", "The ABC Corp"); but I want @a = ("AA Corp, "The ABC Corp", "BB Corp"); How do I sort array without changing... (2 Replies)
Discussion started by: photon
2 Replies
Login or Register to Ask a Question