Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to sort a content of a text file using a shell script? Post 302928007 by nkarthik_mnnit on Monday 8th of December 2014 08:13:38 AM
Old 12-08-2014
Here is the list of 59 entries which is the sample input. I need this list to be sorted as explained below.

Code:
fap022-curtis.feitty
fap0217-dawn.kalani
fap0253-Debbie.Miller
fap0284-Donald.Gray
fap0285-Elaine.Barnes
fap0285-Elaine.Shoudy
fap0285-elizabeth.cabezas
fap0289-Elizabeth.Mavery
fap0299-evan.graham
fap0300-francis.schuckman
NMDemo164-llonjon
NMDemo217-mgrant
NMDemo217-mpinsent
NMDemo217-nrienks
NMDemo217-pcampbell
NMDemo217-pcurrey
NMDemo217-pkoch
NMDemo400-plee
NMDemo599-pmanger
NMDemo655-pnroman
NMDemo017-pschaefer
NMTalent6-gcook
NMTalent6-hatsma
NMTalent4-hdrechsler
NMTalent600-hhartmann
NMTalent3-hhay
NMTalent002-hmanager
NMTalent971-hmatsui
unit1700-zahrms
unit1732-exists
unit1788-accountinquiry
unit1788-adb
unit1625-admissions
unit1234-alert
unit100-auhrms
psf03-LMCKINLEY
psf037-LMULLEN
psf0377-LNILS
psf0378-LPARKER
psf0378-LPEABODY
psf0399-LPEPPER
psf0254-LROBERTS
sbl03400-tnance
sbl0383-tsmythe
sbl0310-vtaylor
sbl03-wmimms
sbl0310-exists
jde0261-ACCTPAY
jde0261-ACCTREV
jde024-AUST
jde0289-BIDDER1
jde0100-BIDDER2
jde0009-BUYER1
adsweb_noreplies
webmaster
dm
bg
rd
jm

These entries can be classified into the following.

10 entries of the type 'fap'
11 entries of the type 'NMDemo'
7 entries of the type 'NMTalent'
7 entries of the type 'unit'
7 entries of the type 'psf'
5 entries of the type 'sbl'
6 entries of the type 'jde'
6 unclassified entry (the last 6 in the list)

each entry of any type is followed by a numeric which represents its environment. eg : In psf0254-LROBERTS, psf is type and 0254 is the environment

two entries of a type may have the same environments. eg: jde0261-ACCTPAY & jde0261-ACCTREV are different entries but share the same environment 0261

Now, I would like to have the following input sorted and the output like below.

Code:
type            env	   count
-----            ----	   ------
fap              8	   10
NMDemo           6	   11
NMTalent         6	   7
unit	         6	   7
psf	         6	   7
sbl	         4	   5
jde	         5	   6
unclassified	 N/A	   6

NOTE 1 : The 'count' column should the total number of entries under a particular type.
NOTE 2 : The 'env' column shows the number of unique environments in a type. eg : fap got 10 entries but 8 unique environments.
NOTE 3 : the 'unclassified' type does not have any environment associated and hence contains all the 'non-type' values
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to edit the content of a file

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)
Discussion started by: tiger99
3 Replies

2. Shell Programming and Scripting

Sort content of text file based on date?

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)
Discussion started by: KidCactus
19 Replies

3. Shell Programming and Scripting

Problem getting the content of a file in a shell script variable

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)
Discussion started by: DushyantG
4 Replies

4. UNIX for Dummies Questions & Answers

creating text file with content from script

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)
Discussion started by: s3270226
0 Replies

5. Shell Programming and Scripting

Shell script to remove some content in a file

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)
Discussion started by: Mr_47
4 Replies

6. Shell Programming and Scripting

Need to build Shell Script to search content of a text file into a folder consist several files

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)
Discussion started by: mukesh.baranwal
3 Replies

7. Shell Programming and Scripting

Script to create a text file whose content is the text of another files

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)
Discussion started by: tenteyu
1 Replies

8. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

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)
Discussion started by: neha0785
5 Replies

9. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

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)
Discussion started by: DIps
3 Replies

10. Homework & Coursework Questions

Shell script/awk to sort text

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)
Discussion started by: ektorzoza
4 Replies
ACL_VALID(3)						   BSD Library Functions Manual 					      ACL_VALID(3)

NAME
acl_valid -- validate an ACL LIBRARY
Linux Access Control Lists library (libacl, -lacl). SYNOPSIS
#include <sys/types.h> #include <sys/acl.h> int acl_valid(acl_t acl); DESCRIPTION
The acl_valid() function checks the ACL referred to by the argument acl for validity. The three required entries ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER must exist exactly once in the ACL. If the ACL contains any ACL_USER or ACL_GROUP entries, then an ACL_MASK entry is also required. The ACL may contain at most one ACL_MASK entry. The user identifiers must be unique among all entries of type ACL_USER. The group identifiers must be unique among all entries of type ACL_GROUP. RETURN VALUE
The acl_valid() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indi- cate the error. ERRORS
If any of the following conditions occur, the acl_valid() function returns -1 and sets errno to the corresponding value: [EINVAL] The argument acl is not a valid pointer to an ACL. The argument acl does not point to a valid ACL. One or more of the required ACL entries is not present in acl. The ACL contains entries that are not unique. STANDARDS
IEEE Std 1003.1e draft 17 ("POSIX.1e", abandoned) SEE ALSO
acl_check(3), acl_set_file(3), acl(5) AUTHOR
Derived from the FreeBSD manual pages written by Robert N M Watson <rwatson@FreeBSD.org>, and adapted for Linux by Andreas Gruenbacher <a.gruenbacher@computer.org>. Linux ACL March 23, 2002 Linux ACL
All times are GMT -4. The time now is 01:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy