Mainframe Sort - Getting count based on field - mainframe

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?

Related

How to sort and ignore spaces?

I'm trying to sort a file but I can't get the results I want.
I have this file :
742550111 aaa aaa aaa aaa aaa 2008 3 1 1
5816470687 aa a dissertation for the 933 2 2 2
Each field is separated by a tabulation, and I would like to sort on the second column.
When I try sort test.txt -t\t -k 2, the output is the same as in the file.
But the output I want to have is :
5816470687 aa a dissertation for the 933 2 2 2
742550111 aaa aaa aaa aaa aaa 2008 3 1 1
I think that's because sort ignores the spaces between the words.
So I tried with this command : LC_ALL=C sort test.txt -t\t -k 2, but it still doesn't work.
Do you have any ideas ?
Bash replaces $'\t' with a real tab:
LC_ALL=C sort file -t $'\t' -k 2
Output:
5816470687 aa a dissertation for the 933 2 2 2
742550111 aaa aaa aaa aaa aaa 2008 3 1 1

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.

get paragraph with awk, and start-of-line regexp

I use awk to get paragraphs from a textfile, like so:
awk -v RS='' -v ORS='\n\n' '/pattern/' ./textfile
Say I have the following textfile:
aaa bbb ccc
aaa bbb ccc
aaa bbb ccc
aaa ccc
bbb aaa ccc
bbb aaa ccc
ccc bbb aaa
ccc bbb aaa
ccc bbb aaa
Now I only want the paragraph with one of the (original) lines starting with "bbb" (hence the second paragraph). However - using regexp ^ will not work anymore, (I presume) because of the RS='' line; awk now only matches to the begin of the paragraph.
Is there another way?
^ means start-of-string. You want start-of-line which is (^|\n), e.g.:
$ awk -v RS='' -v ORS='\n\n' '/(^|\n)bbb/' file
aaa ccc
bbb aaa ccc
bbb aaa ccc

Insert a line before specific ID and renumerate ID column

A file contains ID, Name and other columns. I want to insert a row containing name with details before a specific ID. Then ID column should be updated with proper ID sequence.
Example
Sample File content:
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 XXX ...
5 YYY ...
6 ZZZ ...
Footer
I want to insert MMM ... before ID #4 i.e. before a row 4 XXX ...
Desired output:
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM ...
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer
I could do proper insert using following command but not sure how to update ID column with proper numbering.
sed '/^\s*4/ i 4 MMM ...' file
It would be appreciable if you could help me solve this problem.
One option can be:
awk '/^4/ {print ++i, "MMM"} /^[0-9]/ {$1=++i} 1' file
Explanation
/^4/ {print ++i, "MMM"} on line starting with 4, print MMM with an incremental value.
/^[0-9]/ {$1=++i} on lines starting with number, set first field to an incremental value.
1 print line
Test
$ awk '/^4/ {print ++i, "MMM"} /^[0-9]/ {$1=++i} 1' file
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer
$ awk '/^4 /{print "4 MMM ..."; inc=1} /^[[:digit:]]/{$1+=inc} 1' file
Header1
Header2
1 AAA ...
2 BBB ...
3 CCC ...
4 MMM ...
5 XXX ...
6 YYY ...
7 ZZZ ...
Footer

How to replace the character I want in a line

1 aaa bbb aaa
2 aaa ccccccccc aaa
3 aaa xx aaa
How to replace the second aaa to yyy for each line
1 aaa bbb yyy
2 aaa ccccccccc yyy
3 aaa xx yyy
Issuing the following command will solve your problem.
:%s/\(aaa.\{-}\)aaa/\1yyy/g
Another way would be with \zs and \ze, which mark the beginning and end of a match in a pattern. So you could do:
:%s/aaa.*\zsaaa\ze/yyy
In other words, find "aaa" followed by anything and then another "aaa", and replace that with "yyy".
If you have three "aaa"s on a line, this won't work, though, and you should use \{-} instead of *. (See :h non-greedy)

Resources