Using awk to sort a file alphabetically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using awk to sort a file alphabetically
# 1  
Old 11-21-2014
Using awk to sort a file alphabetically

I have a problem with my homework I need to create a shell script using
Code:
#!bin/awk -f

the script will output the file in an alphabetical order only words and after the word is
Code:
:

after that a space then
Code:
,

then it will be numbered each character by which line its been for example

Code:
CB
92A 
A
BFG How Are You 
B Are 
C 
C Are
.
.B

It should be
Code:
A: 3, 4
Are: 5, 6, 8
B: 6, 10
BFG: 5
C: 1, 7, 8
CB: 2
How: 5
You: 5

I have tried this, but saddunly it did not work
Code:
 #!bin/awk -f
{
split($0, char);
print $0;
sort;
}


I'm using linux

---------- Post updated at 02:41 PM ---------- Previous update was at 12:05 AM ----------

^^ UP

Last edited by collapse; 11-21-2014 at 12:17 AM..
# 2  
Old 11-21-2014
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter and sort the file using awk

I have file and process it and provide clean output. input file Device Symmetrix Name : 000A4 Device Symmetrix Name : 000A5 Device Symmetrix Name : 000A6 Device Symmetrix Name : 000A7 Device Symmetrix Name : 000A8 Device Symmetrix Name : 000A9 Device Symmetrix Name ... (10 Replies)
Discussion started by: ranjancom2000
10 Replies

2. UNIX for Dummies Questions & Answers

Sort alphabetically starting from specified letter

Hi. I'm trying to sort a list of items in a file alphabetically but starting from the letter 'X'. For instance if I had the following file; test.txt Z A T W Y B S X I would like the output to look like; X Y (8 Replies)
Discussion started by: mmab
8 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Reverse the order of a list of file names (but not sort them alphabetically or numerically)

Hello all, I have a list of file names in a text document where each file name consists of 4 letters and 3 numbers (for example MACR119). There are 48 file names in the document (they are not in alphabetical or numerical order). I would like to reorder the list of names so that the 48th name is... (3 Replies)
Discussion started by: MDeBiasse
3 Replies

4. Shell Programming and Scripting

Sort alphabetically, then numerically

Greetings - I'm not necessarily new to bash scripting - I'm probably between beginner and intermediate, but I have something that I just cannot figure out after many attempts to find it. I have a file that is merely a list of many files, with their respective paths, and a branch path (ClearCase)... (5 Replies)
Discussion started by: 1cor29
5 Replies

5. Shell Programming and Scripting

Sort by numbers, then alphabetically

Hey guys, I have a file that contains the following: 366 K 364 Q 12 UB 7 INC. P 4 Law 2 LAMB 2 High 1 QEG 1 OF 1 LC 1 B As you can see, it's already sorted by numerical order, how do I sort it again, breaking the ties by using the alphabetical order of the second column, but... (2 Replies)
Discussion started by: Andrew9191
2 Replies

6. Shell Programming and Scripting

awk -- sort out the out put file

Hi, using awk /sed, I need to sort out the input file. here is the example input file=== Name= shashi | country= india | region = asia | dept= ww Name= jon | region = asia | dept= xx Name=sam | dept= ww Name= anthony | country=england | dept= xx Name= sumo | country= china output... (3 Replies)
Discussion started by: hegdeshashi
3 Replies

7. UNIX for Dummies Questions & Answers

Sort file alphabetically AND numerically

Hi all. I have 2 files like this: f1 A 10 B 80 C 9 f2 A 11 B 700 C 10 What I want is the concatenation of the two files sorted by name (alphabetically) and size (numerically), so the result should be like this: F3 (cat f1 f2 sorted) A 10 A 11 B 80 B 700 (2 Replies)
Discussion started by: mrodrig
2 Replies

8. UNIX for Dummies Questions & Answers

How to sort alphabetically after finding values

I have a list of people in a usage log and need to print the names and phone numbers of people with over 500 logins. I'd also like to display these names alphabetically. I have their total logins set to a variable named total. So far, I have very little in my awk script to do this: FS=":"... (4 Replies)
Discussion started by: doubleminus
4 Replies

9. Shell Programming and Scripting

Sort a file line by line alphabetically

infile: z y x c b a desired output: x y z a b c I don't want to sort the lines into this: a b c x y z nor this: c b a z y x The number of fields per line and number of lines is indeterminate. The field separator is always a space. Thanks for the use of your collective brains.... (11 Replies)
Discussion started by: H2OBoodle
11 Replies

10. UNIX for Dummies Questions & Answers

awk: redrect printf to file and sort

{ printf "%s %6.2f\n", UserName, pay > payroll_report | sort -nk2 payroll_report; } this is what I have but it doesnt write the payroll_report file and gives a syntax error for the pipe...help?? (2 Replies)
Discussion started by: knc9233
2 Replies
Login or Register to Ask a Question