How could I use sed
to find all lines that don't have exactly 35 occurrences of the "|" character?
If I can't use sed
, what could I use?
I'd use awk
as it's more readable and doesn't involve nasty regular expression syntax:
awk -F'|' 'NF != 36' filename
Or grep
:
grep -v '^\([^|]*|\)\{35\}[^|]*$' filename
But if you want to use sed
:
sed '/^\([^|]*|\)\{35\}[^|]*$/d' filename
Here's something you could try:
perl -ne 'print unless (split(/|/, $_)==36);' your_input_file
Splits each line at |
and counts the number of resulting parts. If there are 36, you've got 35 |
and the line is not printed. Otherwise, the line is printed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.