How to sort a content of a text file using a shell script?
I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting.
I've attached the 'Input file' and the 'expected output' to this thread.
Details provided in the expected output file will provide details on how the sort needs to be done.
Basically I need the count (in many parts) of the data in the output. The input file contains 565075 entries hence the addition of all the count of <application> should be equal to 565075 (refer to output file attached for details).
What you want to achieve is way beyond sorting. So, text manipulation languages like awk, perl etc. would be candidates. And, I'd propose you put the specification to your request into the post, not into an attached file.
I am unable to use 'awk'. I would not be interested to use perl here. I would like this to be done on an unix environment using a shell script. Someone please help me with the output script.
Last edited by nkarthik_mnnit; 12-04-2014 at 06:38 AM..
Is this a homework assignment? Posts requesting help and not allowing use of utilities like awk (which is a standard UNIX utility available on all UNIX and Linux systems) frequently means that your professor is placing certain restriction on the tools to be used for an assignment. Homework assignments must follow the rules for the homework forum.
If this is not a homework assignment, as RudiC suggested, please post the requirements for your task in a post; not hidden in two attached files that will consume over 1.75Mb of space on the system of any volunteers here who might be willing to help you solve your problem.
From a distance, putting the data into an associative array intrinsically sorts it. Putting it intoa normal, integer indexed array allows you to sort it using simple sorts like the bubble sort or a bisection insertion sort.
The right solution is divining what the professor wants. Better is OK if prof has a sense of humor or honor.
bsi, fap, unit etc are 'app'
the numeric following the app name is the 'env'
the name after the hypen is the 'user'
There might also be other values not of the format given above. e.g user1,user2
I need the data to be sorted in the following format
Code:
app name number of env total count
----------- ---------------- ------------
NOTE : If 'app' value is fap,bsi etc, it should list all the unique environments in the 'env' column. e.g: the value of env is 5 for app name 'fap' as the number of unique env for fap is 5.
Total count should give the number of entries under the particular app. e.g: fap = 6, bsi = 2
The entries not falling under any app (not of the format '<app><env>-<user>'), e.g: user1, user2 should be put under the separate count list named 'non-app'. Here, the non-app count is 2.
---------------------------------------------------------------------------------------------------
I have 565075 entries which needs to be sorted. A sample script which will sort entries for such huge input will help me.
This is not a homework. I'm running my own business and this will help me with it.
Badly require this forum's expert help!
Moderator's Comments:
Please use CODE tags for all sample input, output, and code samples. Without CODE tags, sequences of spaces and tabs are converted to a single space by normal HTML processing.
Last edited by Don Cragun; 12-08-2014 at 07:12 AM..
Reason: Add CODE tags.
1. The problem statement, all variables and given/known data:
I have a file with a fragment of a novel, which I have to clear from punctuation and sort all the words contained one per line and non duplicated, all this going to a file called "palabras".
Here is fragment of the input file:
... (4 Replies)
Hi Guru's,
I am new to shell scripting. I have a unique requirement:
The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this:
Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end
Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Hi
I am looking for a help in designing a bash script on linux which can do below:-
1) Look in a specific directory for any new files
2) Mail the content of the new file
Appreciate any help
Regards
Neha (5 Replies)
Hello everyone,
I work under Ubuntu 11.10 (c-shell)
I need a script to create a new text file whose content is the text of another text files that are in the directory $DIRMAIL at this moment.
I will show you an example:
- On the one hand, there is a directory $DIRMAIL where there are... (1 Reply)
Have to read one file say sourcefile containing several words and having another folder containing several files.
Now read the first word of Sourcefile & search it into the folder consisting sevral files, and create another file with result. We hhave to pick the filename of the file in which... (3 Replies)
How can I remove all data that contain domain e.g zzgh@something.com, sdd@something.com.my and gg@something.my in one file? so that i only have data without the domain in the file.
Here is the file structure "test.out"
more test.out
1 zzztop@b.com
1 zzzulll
1 zzzullll@s.com.my
... (4 Replies)
hi,
can somebody tell me how I can create a text file with content from Bash script.
The file should be prefilled with information such as current date and time then leaving the user ability to input more data right below those prefilled content.
thank you :) (0 Replies)
Hi,
I have a text file that has a long multi-line db2 CTE query. Now I want to store all the contents of this file (i.e. the entire query) in a shell script variable. I am trying to achieve it by this: query = `cat /Folder/SomeFile.txt` But when I echo the contents of this file by saying echo... (4 Replies)
I now have a 230,000+ lines long text file formatted in segments like this:
Is there a way to sort this file to have everything in chronological order, based on the date and time in the text? In this example, I would like the result to be: (19 Replies)
Hi
I need some help using shell script to edit a file.
My original file has the following format:
/txt/email/myemail.txt
/txt/email/myemail2.txt
/pdf/email/myemail.pdf
/pdf/email/myemail2.pdf
/doc/email/myemail.doc
/doc/email/myemail2.doc
I need to read each line. If the path is... (3 Replies)