I have a file(input.txt) and trying to format as output.txt. See the attached file format.
Note: This is a windows file (DOS format) and the commands are also going to execute on windows.
Basically I am trying to capture all the data in between Local Group Memberships and Global Group Memberships. Then remove unnecessary strings like * from beginning of each string.
Welcome to forum, following may help you in same.
EDIT: Adding code to remove garbage chars thanks to RudiC for reminding same.
tr -d '\r' < Input_file OR
awk '{gsub(/\r/,X,$0);print}' Input_file > Input_file1
Then can run then following.
awk '($0 ~ /Local Group Memberships /){A=1} /Global Group memberships/{A=0} A{sub(/Local Group Memberships +/,X,$0);gsub(/ +/,X,$0);gsub(/^\*/,Z,$0);gsub(/\*/,"\n",$0);print $0}' Input_file1
Your commands were worked fine on windows server If it is installed with any shell application(the machine against which I tested earlier have a shell application installed and thus awk & sed commands were recognized).
But we may have all the machines with that application installed and awk is failed to execute as OS unable to understand this command.
Below is the script working fine w/ machines installed with shell application.
net users Admin > c:\groupList.txt
awk '{gsub(/\r/,X,$0);print}' c:\groupList.txt > c:\groupList1.txt
awk '/Local Group Memberships/ {A=1}/Global Group memberships/ {A=0} A{ match($0,/\*.*/);B=substr($0,RSTART,RLENGTH);sub(/\*/,X,B);sub(/[[:space:]]\*/,"\n",B); print B }' c:\groupList1.txt > c:\groupListTemp.txt
sed -e 's/ *$//g' c:\groupListTemp.txt > c:\groupListTemp1.txt
for /f "usebackq delims=" %%X in ("c:\groupListTemp1.txt") do (NET LOCALGROUP "%%X" Admin /delete)
Would you mind to assist in changing above awk and sed command to windows equivalent commands.
If you want to avoid all the ugliness of the full path to awk, you need to update your PATH variable to include the path to the directory where awk is located, then you can just type awk to run your programs.
Go to Control Panel->System->Advanced and set your PATH environment variable to include "C:\Program Files (x86)\GnuWin32" at the end (separated by a semi-colon) from previous entry. You can download and run the setup file. This should install your AWK in "C:\Program Files (x86)\GnuWin32" . You can run the awk or gawk command from the bin folder or add the folder C:\Program Files (x86)\GnuWin32\bin to your PATH.
We can't install any 3rd party application in those servers due to organization standard and security policy. So for few servers awk and sed command will not work. We need to find windows equivalence command may be commands that support batch programming syntax.
I find a command like findstr equivalent to awk in shell but it not getting exact syntax to capture all data in between specified strings(Local Group Memberships and Global Group Memberships)
In the previous reply there is a typo. actually I meant to say we may not but mentioned we may.
"We may not have all the machines with that application installed and awk is failed to execute as OS unable to understand this command. "