AWK printing columns based on column number and pattern match condition

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to reformat the output of the following command using awk for static and dynamic column numbers:
ps -eopid,lstart,cmd | grep java |grep -v grep
following would be sample input to the awk command:
17524 Wed May 9 08:50:37 2018 /opt/java/latest/bin/java -client -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -Djava.security.policy=/app/oracle/wls1036/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.system.BootIdentityFile=/projects/domainName/servers/AdminServer/security/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Xverify:none -da -Dplatform.home=/app/oracle/wls1036/wlserver_10.3 -Dwls.home=/app/oracle/wls1036/wlserver_10.3/server -Dweblogic.home=/app/oracle/wls1036/wlserver_10.3/server -Ddomain.home=/projects/domainName -Does.client.home=/app/oracle/wls1036/oesclient -Doracle.home=/app/oracle/wls1036/oesclient -Doracle.security.jps.config=/projects/mydomain/config/oeswlssmconfig/AdminServer/jps-config.xml -Dweblogic.management.discover=true -Dwlw.iterativeDev= -Dwlw.testConsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=/app/oracle/wls1036/patch_wls1036/profiles/default/sysext_manifest_classpath:/app/oracle/wls1036/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
Sample Output:
24519 Wed May 9 23:50:09 2018 -Dweblogic.Name=AdminServer
Issue: I am able to print the value of initial PID, Startup date and time based on the column number using awk but the last value's column number can be different in cases(eg: column9 in one output and column 17 in another). How can i print the last value searching corresponding column number containing keyword "-Dweblogic.Name=" and add to the existing output. Combining output for column numbers and column search is throwing exception.
Any easier way to format this output is welcome too using (sed,grep,cut etc).
shell-script awk sed grep
add a comment |Â
up vote
0
down vote
favorite
I need to reformat the output of the following command using awk for static and dynamic column numbers:
ps -eopid,lstart,cmd | grep java |grep -v grep
following would be sample input to the awk command:
17524 Wed May 9 08:50:37 2018 /opt/java/latest/bin/java -client -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -Djava.security.policy=/app/oracle/wls1036/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.system.BootIdentityFile=/projects/domainName/servers/AdminServer/security/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Xverify:none -da -Dplatform.home=/app/oracle/wls1036/wlserver_10.3 -Dwls.home=/app/oracle/wls1036/wlserver_10.3/server -Dweblogic.home=/app/oracle/wls1036/wlserver_10.3/server -Ddomain.home=/projects/domainName -Does.client.home=/app/oracle/wls1036/oesclient -Doracle.home=/app/oracle/wls1036/oesclient -Doracle.security.jps.config=/projects/mydomain/config/oeswlssmconfig/AdminServer/jps-config.xml -Dweblogic.management.discover=true -Dwlw.iterativeDev= -Dwlw.testConsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=/app/oracle/wls1036/patch_wls1036/profiles/default/sysext_manifest_classpath:/app/oracle/wls1036/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
Sample Output:
24519 Wed May 9 23:50:09 2018 -Dweblogic.Name=AdminServer
Issue: I am able to print the value of initial PID, Startup date and time based on the column number using awk but the last value's column number can be different in cases(eg: column9 in one output and column 17 in another). How can i print the last value searching corresponding column number containing keyword "-Dweblogic.Name=" and add to the existing output. Combining output for column numbers and column search is throwing exception.
Any easier way to format this output is welcome too using (sed,grep,cut etc).
shell-script awk sed grep
The last column in awk is$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.
â NickD
May 9 at 14:31
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to reformat the output of the following command using awk for static and dynamic column numbers:
ps -eopid,lstart,cmd | grep java |grep -v grep
following would be sample input to the awk command:
17524 Wed May 9 08:50:37 2018 /opt/java/latest/bin/java -client -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -Djava.security.policy=/app/oracle/wls1036/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.system.BootIdentityFile=/projects/domainName/servers/AdminServer/security/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Xverify:none -da -Dplatform.home=/app/oracle/wls1036/wlserver_10.3 -Dwls.home=/app/oracle/wls1036/wlserver_10.3/server -Dweblogic.home=/app/oracle/wls1036/wlserver_10.3/server -Ddomain.home=/projects/domainName -Does.client.home=/app/oracle/wls1036/oesclient -Doracle.home=/app/oracle/wls1036/oesclient -Doracle.security.jps.config=/projects/mydomain/config/oeswlssmconfig/AdminServer/jps-config.xml -Dweblogic.management.discover=true -Dwlw.iterativeDev= -Dwlw.testConsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=/app/oracle/wls1036/patch_wls1036/profiles/default/sysext_manifest_classpath:/app/oracle/wls1036/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
Sample Output:
24519 Wed May 9 23:50:09 2018 -Dweblogic.Name=AdminServer
Issue: I am able to print the value of initial PID, Startup date and time based on the column number using awk but the last value's column number can be different in cases(eg: column9 in one output and column 17 in another). How can i print the last value searching corresponding column number containing keyword "-Dweblogic.Name=" and add to the existing output. Combining output for column numbers and column search is throwing exception.
Any easier way to format this output is welcome too using (sed,grep,cut etc).
shell-script awk sed grep
I need to reformat the output of the following command using awk for static and dynamic column numbers:
ps -eopid,lstart,cmd | grep java |grep -v grep
following would be sample input to the awk command:
17524 Wed May 9 08:50:37 2018 /opt/java/latest/bin/java -client -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -Djava.security.policy=/app/oracle/wls1036/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.system.BootIdentityFile=/projects/domainName/servers/AdminServer/security/boot.properties -Dweblogic.nodemanager.ServiceEnabled=true -Xverify:none -da -Dplatform.home=/app/oracle/wls1036/wlserver_10.3 -Dwls.home=/app/oracle/wls1036/wlserver_10.3/server -Dweblogic.home=/app/oracle/wls1036/wlserver_10.3/server -Ddomain.home=/projects/domainName -Does.client.home=/app/oracle/wls1036/oesclient -Doracle.home=/app/oracle/wls1036/oesclient -Doracle.security.jps.config=/projects/mydomain/config/oeswlssmconfig/AdminServer/jps-config.xml -Dweblogic.management.discover=true -Dwlw.iterativeDev= -Dwlw.testConsole= -Dwlw.logErrorsToConsole= -Dweblogic.ext.dirs=/app/oracle/wls1036/patch_wls1036/profiles/default/sysext_manifest_classpath:/app/oracle/wls1036/patch_ocp371/profiles/default/sysext_manifest_classpath weblogic.Server
Sample Output:
24519 Wed May 9 23:50:09 2018 -Dweblogic.Name=AdminServer
Issue: I am able to print the value of initial PID, Startup date and time based on the column number using awk but the last value's column number can be different in cases(eg: column9 in one output and column 17 in another). How can i print the last value searching corresponding column number containing keyword "-Dweblogic.Name=" and add to the existing output. Combining output for column numbers and column search is throwing exception.
Any easier way to format this output is welcome too using (sed,grep,cut etc).
shell-script awk sed grep
edited May 16 at 4:36
asked May 9 at 14:18
Dexter
165
165
The last column in awk is$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.
â NickD
May 9 at 14:31
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55
add a comment |Â
The last column in awk is$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.
â NickD
May 9 at 14:31
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55
The last column in awk is
$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.â NickD
May 9 at 14:31
The last column in awk is
$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.â NickD
May 9 at 14:31
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
to get column, use a loop
| awk 'for(i=$NF;i>1;i--)
if ( $i ~ /-Dweblogic.name/ ) wln=$i; break ;
printf "... %s ...",wln'
where
$NFis last fieldfor( )construct will loop from end of line to begin$i ~ /-Dweblogic.name/match -Dweblogic.name=admin1 , -Dweblogic.name=otheradmin (you may want /^-D/ to not match yourself)
may I sugest you drop grep java | grep -v grep to grep [j]ava witch will not grep itslef (and amaze coworker), or
| awk '/java/ ... '
or, to have a mainimal number of arg :
| awk '/java/ && NF>10 ... '
add a comment |Â
up vote
0
down vote
Perhaps you can search Dweblogic with grep and after with sed
search="-Dweblogic.Name="
ps -eopid,lstart,cmd |
grep "java.*$search" |
sed -E 's#([^/]* )/.*('"$search"'[^ ]*).*#12#'
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
to get column, use a loop
| awk 'for(i=$NF;i>1;i--)
if ( $i ~ /-Dweblogic.name/ ) wln=$i; break ;
printf "... %s ...",wln'
where
$NFis last fieldfor( )construct will loop from end of line to begin$i ~ /-Dweblogic.name/match -Dweblogic.name=admin1 , -Dweblogic.name=otheradmin (you may want /^-D/ to not match yourself)
may I sugest you drop grep java | grep -v grep to grep [j]ava witch will not grep itslef (and amaze coworker), or
| awk '/java/ ... '
or, to have a mainimal number of arg :
| awk '/java/ && NF>10 ... '
add a comment |Â
up vote
0
down vote
to get column, use a loop
| awk 'for(i=$NF;i>1;i--)
if ( $i ~ /-Dweblogic.name/ ) wln=$i; break ;
printf "... %s ...",wln'
where
$NFis last fieldfor( )construct will loop from end of line to begin$i ~ /-Dweblogic.name/match -Dweblogic.name=admin1 , -Dweblogic.name=otheradmin (you may want /^-D/ to not match yourself)
may I sugest you drop grep java | grep -v grep to grep [j]ava witch will not grep itslef (and amaze coworker), or
| awk '/java/ ... '
or, to have a mainimal number of arg :
| awk '/java/ && NF>10 ... '
add a comment |Â
up vote
0
down vote
up vote
0
down vote
to get column, use a loop
| awk 'for(i=$NF;i>1;i--)
if ( $i ~ /-Dweblogic.name/ ) wln=$i; break ;
printf "... %s ...",wln'
where
$NFis last fieldfor( )construct will loop from end of line to begin$i ~ /-Dweblogic.name/match -Dweblogic.name=admin1 , -Dweblogic.name=otheradmin (you may want /^-D/ to not match yourself)
may I sugest you drop grep java | grep -v grep to grep [j]ava witch will not grep itslef (and amaze coworker), or
| awk '/java/ ... '
or, to have a mainimal number of arg :
| awk '/java/ && NF>10 ... '
to get column, use a loop
| awk 'for(i=$NF;i>1;i--)
if ( $i ~ /-Dweblogic.name/ ) wln=$i; break ;
printf "... %s ...",wln'
where
$NFis last fieldfor( )construct will loop from end of line to begin$i ~ /-Dweblogic.name/match -Dweblogic.name=admin1 , -Dweblogic.name=otheradmin (you may want /^-D/ to not match yourself)
may I sugest you drop grep java | grep -v grep to grep [j]ava witch will not grep itslef (and amaze coworker), or
| awk '/java/ ... '
or, to have a mainimal number of arg :
| awk '/java/ && NF>10 ... '
answered May 9 at 15:04
Archemar
18.9k93365
18.9k93365
add a comment |Â
add a comment |Â
up vote
0
down vote
Perhaps you can search Dweblogic with grep and after with sed
search="-Dweblogic.Name="
ps -eopid,lstart,cmd |
grep "java.*$search" |
sed -E 's#([^/]* )/.*('"$search"'[^ ]*).*#12#'
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
add a comment |Â
up vote
0
down vote
Perhaps you can search Dweblogic with grep and after with sed
search="-Dweblogic.Name="
ps -eopid,lstart,cmd |
grep "java.*$search" |
sed -E 's#([^/]* )/.*('"$search"'[^ ]*).*#12#'
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Perhaps you can search Dweblogic with grep and after with sed
search="-Dweblogic.Name="
ps -eopid,lstart,cmd |
grep "java.*$search" |
sed -E 's#([^/]* )/.*('"$search"'[^ ]*).*#12#'
Perhaps you can search Dweblogic with grep and after with sed
search="-Dweblogic.Name="
ps -eopid,lstart,cmd |
grep "java.*$search" |
sed -E 's#([^/]* )/.*('"$search"'[^ ]*).*#12#'
answered May 10 at 15:42
ctac_
1,006116
1,006116
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
add a comment |Â
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
doesn't seem to work when i use it in ssh script block.Is there any escape sequence to help it work. > ssh -q -o "StrictHostKeyChecking no" -t myuserid@$ip << EOF
â Dexter
May 16 at 4:32
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442783%2fawk-printing-columns-based-on-column-number-and-pattern-match-condition%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The last column in awk is
$NF. Other than that, I cannot tell what you want to do because your sample input bears no relation to your sample output.â NickD
May 9 at 14:31
@Nick the output is based on fixed columns ( 24519 Wed May 9 23:50:09 2018) and a not fixed column containing keyword "-Dweblogic.Name=" . i.e (-Dweblogic.Name=AdminServer)
â Dexter
May 9 at 14:55