report if any one record is not of matching size using sed [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
-3
down vote
favorite
how can I use sed
to report any first record that is not of size 21 in a file?
I don't want sed
to scan the complete file and get out as soon as the first record which is not of size 21 is found.
sed
closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59
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
-3
down vote
favorite
how can I use sed
to report any first record that is not of size 21 in a file?
I don't want sed
to scan the complete file and get out as soon as the first record which is not of size 21 is found.
sed
closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59
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.
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
If you read the manual it explains how toq
uitsed
.
â don_crissti
May 16 at 19:02
1
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50
add a comment |Â
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
how can I use sed
to report any first record that is not of size 21 in a file?
I don't want sed
to scan the complete file and get out as soon as the first record which is not of size 21 is found.
sed
how can I use sed
to report any first record that is not of size 21 in a file?
I don't want sed
to scan the complete file and get out as soon as the first record which is not of size 21 is found.
sed
edited May 16 at 19:27
SivaPrasath
4,74212445
4,74212445
asked May 16 at 18:36
Ahmad S
11
11
closed as unclear what you're asking by DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59
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 DopeGhoti, steve, G-Man, dr01, X Tian May 17 at 15:59
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.
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
If you read the manual it explains how toq
uitsed
.
â don_crissti
May 16 at 19:02
1
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50
add a comment |Â
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
If you read the manual it explains how toq
uitsed
.
â don_crissti
May 16 at 19:02
1
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
If you read the manual it explains how to
q
uit sed
.â don_crissti
May 16 at 19:02
If you read the manual it explains how to
q
uit sed
.â don_crissti
May 16 at 19:02
1
1
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
Based on this answer to your previous question
sed -n '/^.21$/! p;q;' file
add a comment |Â
up vote
1
down vote
Using awk
(this would be easiest):
awk 'length != 21 printf("Line of length %d foundn", length); exit ' file
Or, as part of a shell script,
if ! awk 'length != 21 exit 1 ' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Using sed
:
sed -nE '/^.21$/!p;q;' file
With GNU sed
, you would be able to do
if ! sed -nE '/.21$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
add a comment |Â
up vote
1
down vote
With GNU grep
:
if line=$(grep -Exnvm1 '.21' < file); then
printf >&2 'Found "%s" which is not 21 characters longn' "$line"
fi
(-n
above includes the line number)
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Based on this answer to your previous question
sed -n '/^.21$/! p;q;' file
add a comment |Â
up vote
1
down vote
accepted
Based on this answer to your previous question
sed -n '/^.21$/! p;q;' file
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Based on this answer to your previous question
sed -n '/^.21$/! p;q;' file
Based on this answer to your previous question
sed -n '/^.21$/! p;q;' file
answered May 16 at 19:08
steeldriver
31.2k34978
31.2k34978
add a comment |Â
add a comment |Â
up vote
1
down vote
Using awk
(this would be easiest):
awk 'length != 21 printf("Line of length %d foundn", length); exit ' file
Or, as part of a shell script,
if ! awk 'length != 21 exit 1 ' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Using sed
:
sed -nE '/^.21$/!p;q;' file
With GNU sed
, you would be able to do
if ! sed -nE '/.21$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
add a comment |Â
up vote
1
down vote
Using awk
(this would be easiest):
awk 'length != 21 printf("Line of length %d foundn", length); exit ' file
Or, as part of a shell script,
if ! awk 'length != 21 exit 1 ' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Using sed
:
sed -nE '/^.21$/!p;q;' file
With GNU sed
, you would be able to do
if ! sed -nE '/.21$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Using awk
(this would be easiest):
awk 'length != 21 printf("Line of length %d foundn", length); exit ' file
Or, as part of a shell script,
if ! awk 'length != 21 exit 1 ' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Using sed
:
sed -nE '/^.21$/!p;q;' file
With GNU sed
, you would be able to do
if ! sed -nE '/.21$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi
Using awk
(this would be easiest):
awk 'length != 21 printf("Line of length %d foundn", length); exit ' file
Or, as part of a shell script,
if ! awk 'length != 21 exit 1 ' file; then
echo 'Line of length != 21 found (or awk failed to execute properly)'
else
echo 'All lines are 21 characters (or the file is empty)'
fi
Using sed
:
sed -nE '/^.21$/!p;q;' file
With GNU sed
, you would be able to do
if ! sed -nE '/.21$/!q 1' file; then
echo 'Line with != 21 characters found (or sed failed to run properly)'
else
echo 'All lines are 21 characters (or file is empty)'
fi
edited May 16 at 19:12
answered May 16 at 18:42
Kusalananda
102k13199315
102k13199315
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
add a comment |Â
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
using sed please
â Ahmad S
May 16 at 19:00
using sed please
â Ahmad S
May 16 at 19:00
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
@AhmadS See updated answer.
â Kusalananda
May 16 at 19:12
add a comment |Â
up vote
1
down vote
With GNU grep
:
if line=$(grep -Exnvm1 '.21' < file); then
printf >&2 'Found "%s" which is not 21 characters longn' "$line"
fi
(-n
above includes the line number)
add a comment |Â
up vote
1
down vote
With GNU grep
:
if line=$(grep -Exnvm1 '.21' < file); then
printf >&2 'Found "%s" which is not 21 characters longn' "$line"
fi
(-n
above includes the line number)
add a comment |Â
up vote
1
down vote
up vote
1
down vote
With GNU grep
:
if line=$(grep -Exnvm1 '.21' < file); then
printf >&2 'Found "%s" which is not 21 characters longn' "$line"
fi
(-n
above includes the line number)
With GNU grep
:
if line=$(grep -Exnvm1 '.21' < file); then
printf >&2 'Found "%s" which is not 21 characters longn' "$line"
fi
(-n
above includes the line number)
answered May 16 at 21:36
Stéphane Chazelas
279k53513845
279k53513845
add a comment |Â
add a comment |Â
i have the sed command i am not sure how to break out of it .
â Ahmad S
May 16 at 19:00
If you read the manual it explains how to
q
uitsed
.â don_crissti
May 16 at 19:02
1
Possible duplicate of sed command to find lines which are not of specific size
â DopeGhoti
May 16 at 19:31
@DopeGhoti - no, that is a different question that asks how to print all lines. The fact that you changed your answer there to answer the question here after a comment made by the OP doesn't change that (though your one liner there is better that the ones here).
â don_crissti
May 16 at 19:37
In fairness, this is a duplicate of what the other question was apparently meant to be as opposed to what the other question is stated to be.
â DopeGhoti
May 16 at 19:50