Shiva wrote:
> Hello everyone! Been some time since I visited here and so much has happened. From the last time here I've developed so many small tools that will help newbies like me. Learnt more about tacl programming as well. Learning more everyday. All thanks to you people.
>
> To my question now. Again a mainframe similarity that I'm trying to find in tandem. When I search for some string in a file using the mainframe TSO command, I used to get the 'number' of times the string was found, as well. Though this detail might seem unnecessary, I still got it. TEDIT's search doesn't seem to tell me that. Neither does EDIT's command - though it displays the list of lines where it is found. Is writing a macro/routine the only way around this? Or is there a way in both EDIT & TEDIT - which seems highly unlikely at this point.
>
I can only tell you the shortest way I know to get the result in EDIT. TEDIT might have a way to do it, but I do not know TEDIT very well.
In EDIT, I believe this sequence of commands will get the count:
EDIT file; PUT temp /some string/; GET temp; NUMBER ALL; LIST LAST; EXIT
this will put all lines that match "some string" into the file "temp", open temp, renumber the lines in the file to start with 1 and increment by 1, then display the last line in the file. The line number of that last file will be the number of times "some string" appears in the original file.
If you are willing to use unsupported programs, such as LOCATE, I believe it has an option to count matches, so you could get the count in a single LOCATE command, if LOCATE is installed on your system.
In OSS, you would do something like this:
grep "some string" file | wc -l
This would print lines from "file" that match "some string", and that output would not be displayed, but would be sent to the wc program. The -l flag makes wc count the lines in its input and display the count when it reaches the end of input. "file" could be /G/vol/subvol/file to make it work on Guardian files
Neither of those are single editor commands, so if you need to get the count while you are in the midst of editing a file, you would have to exit the editor in order to run
>
> And one more functionality of mainframe which I used to adore is the TSO command - NX ALL F ALL 'search_string'
>
> For the non-mainframers, this command would delete or rather exclude all those lines except those which have the string which is searched. For example, if you search for 'Robin' in a file. All the lines except those which have the word robin will be deleted. I tried this with so many combinations of commands in TDIT but was unsuccessful, without using copy/retrieve - mainly because I don't want to create or use another file - when I can do that using just one file in mainframe, I'd like to do the same in NS. But finding it hard. Again, only a macro is the only way?
>
If I understand what the command you describe does, EDIT certainly can do it:
EDIT file; DELETE QUIET NOT /Robin/; EXIT;
I imagine TEDIT has a way to delete lines that do not match a string, but I don't know TEDIT well enough to know it. Perhaps someone who knows TEDIT better than I do will answer that part of the question.