Purchase Solution

Unix command to sort a file based on a certain column numerically

Not what you're looking for?

Ask Custom Question

Please see the attached file for the complete problem.
Please help me with this programming question:
Create a single command string that will modify the file called myfile and change all occurrences of the ! to a :. The command string must also sort the file numerically on the GID field and then save the output to a file called newfile.
Replace the ## in the command string below with the correct characters to make the above described work.
sed 's/!/:/g' myfile | sort -### -t: > ~/newfile

Attachments
Purchase this Solution

Solution Summary

The solution explains how to use different options with the important Unix sort command to accomplish numerical sorting of a certain field in a field separated file.

Solution Preview

(Please see the attached files for the complete solution).
In order to sort a file according to a certain field, you need to specify a Field Separator or delimiter using -t.
Since the GID values are numbers, we need to specify another sorting option "n".
Finally, we want to sort the file according to the third field (the GID field), therefore, we need to use the -k option which specifies the range of fields to ...

Purchase this Solution


Free BrainMass Quizzes
Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.