the above lines are available in several files in my user.So I have to find and extract them into a log file.so please suggest me how to write a script file for the above issue.
In sqsh syntax, I think you must have "-U" for user name instead -u.
Also, if you are not sure about the order of the flags then you need to consider that case.
awk '
/^sqsh/ {
for (i=1;i<=NF;i++) {
if ( $i ~ /^-U/ ) {
gsub("-U","",$i)
USER[NR] = $i
}
if ( $i ~ /^-P/ ) {
gsub("-P","",$i)
PASSWD[NR] = $i
}
}
}
END {
for (i in USER) { print USER, PASSWD }
} ' *.txt
If you want to consider the files with other patterns also, you can first get the list of all the required files ( find can be useful ) and then read the files one by one.