Using SORT in JCL, require only a maximum count after counting records group by - mainframe

I have a problem, in which I need the max count after performing the group by count of records from position 1 to length 5, in a single step using SORT in JCL.
Tried with below JCL code, and was able to perform the group by count of records, but now only max count record is require, and tried MAX, but for every usage job abends.
Sample Data:
AAAAA 234
AAAAA 124
BBBBB 324
BBBBB 546
AAAAA 325
CCCCC 754
BBBBB 546
BBBBB 346
CCCCC 765
SORT Control statement used in JCL Step:
SORT FIELDS=(1,5,CH,A)
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,5,TRAILER3=(1,5,X,COUNT=(M10,LENGHT=4)))
Current output:
AAAAA 3
BBBBB 4
CCCCC 2
Require output:
BBBBB 4
Could anyone please help and suggest how I can use MAX along with SECTIONS, TRAILER and COUNT in single step.

Related

Extract values from column based on other column EXcel function line code

New to Excel : Problem
Sample table Below :
Company | Product | |Total Sales
AAA QQQ 123
BBB QQQ 140
CCC WWW 127
DDD WWW 145
CCC QQQ 190
DDD QQQ 290
AAA WWW 240
BBB WWW 120
AAA RRR 123
BBB RRR 122
CCC RRR 178
DDD RRR 789
Desired output : Same Table should be sorted by companies and products arranged according to total sales:
(Company names need not to be sorted but should be clumped together)
Desired output:
Company Product Total Sales
AAA WWW 240
AAA QQQ 123
AAA RRR 123
BBB QQQ 140
BBB RRR 122
BBB WWW 120
CCC QQQ 190
CCC RRR 178
CCC WWW 127
DDD QQQ 290
DDD RRR 789
DDD WWW 145
The sheet is too big to do it manually. Is there any way to automate the process in excel . If so Please help. Solution should be by functions only no pivot table or VBA.
It appears that all you want to do is sort your data on the Company and Total Sales columns, in that order. In this case, you can just highlight your table in Excel and then press ALT + D + S. This will bring up a sorting dialog box, as the screen capture below shows. Note: include the column headers when you select the data (despite what the screen capture shows).
Just choose Company as the first sort column, with ascending order (i.e. A to Z, which is the default). Then click Add Level to add a new sort column, and choose Total Sales with Largest to Smallest for the sort order.
Use Excel menu Data >> Filter
select arrow button on header row then select sort type as you wish.
Or you need more sort select like below picture.
Add level and select column which you would like to sort then click OK.
The result should be like this.

Mainframe Sort - Getting count based on field

My requirement is to get the count based on the field.
For example:
AAA 1234
AAA 111
...
AAA 112
BBB 123
BBB 123
...
BBB 333
CCC 333
Output should be:
AAA 2000
BBB 300
CCC 1
I am using the Sort card:
SORT FIELDS=(1,3,CH,A)
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,3,TRAILER3=(1,3,X,COUNT=(M10,LENGTH=10)))
But I need the count to be left justified. Currently the count is displaying with leading spaces.
How can I make these count results left justified?

How to Randomize Columns of a Text File in Linux

I would like to take a text file and for each line randomize the words/columns. The files could contain millions of rows, so efficiency is important. I've tried the Google route, but everything I find is related to sorting lines randomly and not the columns.
For example taking a simple file like this (I'll use numbers, but they could be words):
111 222 333 444 555
555 666 777 888 999 000
000 333 555 777
The output might look the following:
222 111 555 444 333
777 555 666 000 999 888
777 333 000 555
Perl to the rescue:
perl -MList::Util=shuffle -lne 'print join " ", shuffle split' < input.txt > output.txt
-l appends a newline after print
-n process the input line by line
split splits the input line on whitespace
shuffle (from List::Util) shuffles the list randomly
join " " creates one string from the list, putting a space between members.

In AWK, how to split consecutive rows that have the same string as a "record"?

Let's say I have below text.
aaaaaaa
aaaaaaa
bbb
bbb
bbb
ccccccccccccc
ddddd
ddddd
Is there a way to modify the text as the following.
1 aaaaaaa
1 aaaaaaa
2 bbb
2 bbb
2 bbb
3 ccccccccccccc
4 ddddd
4 ddddd
You could use something like this in awk:
$ awk '{print ($0!=p?++i:i),$0;p=$0}' file
1 aaaaaaa
1 aaaaaaa
2 bbb
2 bbb
2 bbb
3 ccccccccccccc
4 ddddd
4 ddddd
i is incremented whenever the current line differs from the previous line. p holds the value of the previous line, $0.
Alternatively, as suggested by JID:
awk '$0!=p{p=$0;i++}{print i,$0}' file
When the current line differs from p, replace p and increment i. See the comments for discussion of the pros and cons of either approach :)
A further contribution (and even shorter!) by NeronLeVelu
$ awk '{print i+=($0!=p),p=$0}' file
This version performs the addition assignment and basic assignment within the print statement. This works because the return value of each assignment is the value that has been assigned.
As pointed out in the comments, if the first line of the file is empty, the behaviour changes slightly. Assuming that the first line should always begin with a 1, the following block can be added to the start of any of the one-liners:
NR==1{p=$0;i=1}
i.e. on the first line, initialise p to the contents of the line (empty or not) and i to 1. Thanks to Wintermute for this suggestion.

How to format text, such that single line will not exceed N characters [duplicate]

This question already has answers here:
vim command to restructure/force text to 80 columns
(6 answers)
Closed 9 years ago.
I want to know what is the best practice to format selected text, such that each column does not exceed N characters.
For example I had this text at the begging (Note the text doesn't exceed 80 columns):
aaaaaaa aaaaa aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa
And then suddenly I had to change the first line and and text like:
BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB
Such the text will become similar to this:
aaaaaaa aaaaa BBBBBB BB B BBB BB BBB BBB BBB BBBB BBBBBBBBBBBB aaaaaa aaaaa aaaaaaa aaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaa
aaaaa aaaaaaa aaaaaa aaaaaaaaa a aaaa aaaaaaaaa aaaaaaa aaaaaaa aaaa
aaaaa aaaaaaa aaaaaaaaa aaaaaaaa aaaaaa aaaaaaaa aaaaa a aaaaaaaaaaaaaa
aaaaaaa aaaa aaaaaaaaaaa aaaaaa aaaaaaaa aaaaaaa aaaaaaaaa aaaaaaaaaa
aaaaaa aaaaaaaaaa aaaaaaaaaaaa aaaaa aaaaa aaaaa aaaaaaaa aaaaa aaa aaaaa
So what is the easiest way to format the text to kind force the limit on columns up to 80 characters?
P.S
I don't wan't to format every line manually.
See here.
Basically, :set tw=80, then use the gq command to reformat preexisting text. To auto-wrap the entire file, go to the first line and type gqG (note capital G).
See this question.
Set textwidth to 80, move to the start of the file (can be done with
Ctrl-Home or gg), and type gqG.
gqG formats the text starting from the current position and to the end
of the file. It will automatically join consecutive lines when
possible. You can place a blank line between two lines if you don't
want those two to be joined together.

Resources