Ignore the half empty line in a file [closed]
up vote
0
down vote
favorite
I have a file which contains lines, in /tmp/file.txt like these:
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>qwer-aa.aa
4>iuyn dfgdfg 123
5>dsfdg-aa.aa
6>tyuh-aa.aa dfsdf
7>sdfjsfs-aa.aa
8>vdgdgdf dddd
What I try to get or make from this file is:
-aa.aa
is not a unique string.
So if there is second or third column, line should be in a file else not.
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
I tried awk and cut commands, but I have not succeed.
This is a script that creates this file which I wrote and every line starts with hostnames and -aa.aa indicates fqdn.
And other things like abcd 2
dfgdfg 123
what I check in servers.
For example root login , ssh protocol and selinux status.
host(){
echo $block1".aa-aa.local"
}
rootlogin() {
if [[ $(sudo cat /etc/ssh/sshd_config | grep -i "PermitRootLogin
yes" | grep -v "#PermitRootLogin yes") = "PermitRootLogin yes" ]]; then
echo "Root Login Detected!!!"
fi
}
firefox(){
firefox=`rpm -qa firefox* | grep -o firefox`
if [[ $firefox = 'firefox' ]]; then
echo "Firefox package detected!!!"
fi
}
echo ""$1" "xyz"| "$(host)"| "$(rootlogin)"| "$(firefox)""
In the beginning of the script I am starting with host name function. So lines starts with hostname.
If the server passes all controls, it should not be in the txt file.
This how I make a txt file from the ansible output.
/bin/cat /tmp/temp.dat | grep xyz | awk -F '|' '{ print $2" " $3}' | awk -F'"' '{ print $1 }' |awk '{print NR "> " $s}' | sort -n >| /tmp/temp.txt
linux shell-script ansible
closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Isaac, G-Man, daisy Nov 27 at 14:39
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
0
down vote
favorite
I have a file which contains lines, in /tmp/file.txt like these:
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>qwer-aa.aa
4>iuyn dfgdfg 123
5>dsfdg-aa.aa
6>tyuh-aa.aa dfsdf
7>sdfjsfs-aa.aa
8>vdgdgdf dddd
What I try to get or make from this file is:
-aa.aa
is not a unique string.
So if there is second or third column, line should be in a file else not.
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
I tried awk and cut commands, but I have not succeed.
This is a script that creates this file which I wrote and every line starts with hostnames and -aa.aa indicates fqdn.
And other things like abcd 2
dfgdfg 123
what I check in servers.
For example root login , ssh protocol and selinux status.
host(){
echo $block1".aa-aa.local"
}
rootlogin() {
if [[ $(sudo cat /etc/ssh/sshd_config | grep -i "PermitRootLogin
yes" | grep -v "#PermitRootLogin yes") = "PermitRootLogin yes" ]]; then
echo "Root Login Detected!!!"
fi
}
firefox(){
firefox=`rpm -qa firefox* | grep -o firefox`
if [[ $firefox = 'firefox' ]]; then
echo "Firefox package detected!!!"
fi
}
echo ""$1" "xyz"| "$(host)"| "$(rootlogin)"| "$(firefox)""
In the beginning of the script I am starting with host name function. So lines starts with hostname.
If the server passes all controls, it should not be in the txt file.
This how I make a txt file from the ansible output.
/bin/cat /tmp/temp.dat | grep xyz | awk -F '|' '{ print $2" " $3}' | awk -F'"' '{ print $1 }' |awk '{print NR "> " $s}' | sort -n >| /tmp/temp.txt
linux shell-script ansible
closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Isaac, G-Man, daisy Nov 27 at 14:39
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file which contains lines, in /tmp/file.txt like these:
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>qwer-aa.aa
4>iuyn dfgdfg 123
5>dsfdg-aa.aa
6>tyuh-aa.aa dfsdf
7>sdfjsfs-aa.aa
8>vdgdgdf dddd
What I try to get or make from this file is:
-aa.aa
is not a unique string.
So if there is second or third column, line should be in a file else not.
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
I tried awk and cut commands, but I have not succeed.
This is a script that creates this file which I wrote and every line starts with hostnames and -aa.aa indicates fqdn.
And other things like abcd 2
dfgdfg 123
what I check in servers.
For example root login , ssh protocol and selinux status.
host(){
echo $block1".aa-aa.local"
}
rootlogin() {
if [[ $(sudo cat /etc/ssh/sshd_config | grep -i "PermitRootLogin
yes" | grep -v "#PermitRootLogin yes") = "PermitRootLogin yes" ]]; then
echo "Root Login Detected!!!"
fi
}
firefox(){
firefox=`rpm -qa firefox* | grep -o firefox`
if [[ $firefox = 'firefox' ]]; then
echo "Firefox package detected!!!"
fi
}
echo ""$1" "xyz"| "$(host)"| "$(rootlogin)"| "$(firefox)""
In the beginning of the script I am starting with host name function. So lines starts with hostname.
If the server passes all controls, it should not be in the txt file.
This how I make a txt file from the ansible output.
/bin/cat /tmp/temp.dat | grep xyz | awk -F '|' '{ print $2" " $3}' | awk -F'"' '{ print $1 }' |awk '{print NR "> " $s}' | sort -n >| /tmp/temp.txt
linux shell-script ansible
I have a file which contains lines, in /tmp/file.txt like these:
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>qwer-aa.aa
4>iuyn dfgdfg 123
5>dsfdg-aa.aa
6>tyuh-aa.aa dfsdf
7>sdfjsfs-aa.aa
8>vdgdgdf dddd
What I try to get or make from this file is:
-aa.aa
is not a unique string.
So if there is second or third column, line should be in a file else not.
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
I tried awk and cut commands, but I have not succeed.
This is a script that creates this file which I wrote and every line starts with hostnames and -aa.aa indicates fqdn.
And other things like abcd 2
dfgdfg 123
what I check in servers.
For example root login , ssh protocol and selinux status.
host(){
echo $block1".aa-aa.local"
}
rootlogin() {
if [[ $(sudo cat /etc/ssh/sshd_config | grep -i "PermitRootLogin
yes" | grep -v "#PermitRootLogin yes") = "PermitRootLogin yes" ]]; then
echo "Root Login Detected!!!"
fi
}
firefox(){
firefox=`rpm -qa firefox* | grep -o firefox`
if [[ $firefox = 'firefox' ]]; then
echo "Firefox package detected!!!"
fi
}
echo ""$1" "xyz"| "$(host)"| "$(rootlogin)"| "$(firefox)""
In the beginning of the script I am starting with host name function. So lines starts with hostname.
If the server passes all controls, it should not be in the txt file.
This how I make a txt file from the ansible output.
/bin/cat /tmp/temp.dat | grep xyz | awk -F '|' '{ print $2" " $3}' | awk -F'"' '{ print $1 }' |awk '{print NR "> " $s}' | sort -n >| /tmp/temp.txt
linux shell-script ansible
linux shell-script ansible
edited Nov 26 at 18:06
asked Nov 26 at 14:58
1010111100011
356
356
closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Isaac, G-Man, daisy Nov 27 at 14:39
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Isaac, G-Man, daisy Nov 27 at 14:39
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11
add a comment |
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
With that sparse a specification, how about
awk 'NF>1 {sub (/^[0-9]/, ++CNT); print }' file
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
If this doesn't satisfy your needs, please become way more precise and detailed in your question.
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
With that sparse a specification, how about
awk 'NF>1 {sub (/^[0-9]/, ++CNT); print }' file
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
If this doesn't satisfy your needs, please become way more precise and detailed in your question.
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
add a comment |
up vote
0
down vote
With that sparse a specification, how about
awk 'NF>1 {sub (/^[0-9]/, ++CNT); print }' file
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
If this doesn't satisfy your needs, please become way more precise and detailed in your question.
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
add a comment |
up vote
0
down vote
up vote
0
down vote
With that sparse a specification, how about
awk 'NF>1 {sub (/^[0-9]/, ++CNT); print }' file
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
If this doesn't satisfy your needs, please become way more precise and detailed in your question.
With that sparse a specification, how about
awk 'NF>1 {sub (/^[0-9]/, ++CNT); print }' file
1>xcd-aa.aa abcd 2
2>rettew-aa.aa asddf sfsd sdg
3>iuyn dfgdfg 123
4>tyuh-aa.aa dfsdf
5>vdgdgdf dddd
If this doesn't satisfy your needs, please become way more precise and detailed in your question.
answered Nov 26 at 16:04
RudiC
3,6371312
3,6371312
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
add a comment |
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
did not work for my case. I do not know how can I give more details because I already shared a sample file and what I want to make with different cases line by line.
– 1010111100011
Nov 26 at 16:57
I added extra information.
– 1010111100011
Nov 26 at 18:03
I added extra information.
– 1010111100011
Nov 26 at 18:03
add a comment |
What's the criteria for inclusion or exclusion?
– Jeff Schaller
Nov 26 at 14:59
@JeffSchaller I edited the question.
– 1010111100011
Nov 26 at 15:06
Are the line numbers part of the file?
– Stephen Harris
Nov 26 at 15:10
@StephenHarris yes.
– 1010111100011
Nov 26 at 15:11