Reputation: 135
I have a specific file (file.txt) with several lines.
How is it possible to delete all lines that do not have 12 characters, using sed?
Upvotes: 1
Views: 51
Reputation: 212424
Not sure why you would use sed
. This is much cleaner in awk:
awk 'length == 12' file.txt
Upvotes: 2
Reputation: 50795
Use an interval expression to specify the exact number of characters you want to match between the beginning (^
) and end ($
) of the input record.
sed '/^.\{12\}$/!d' file
Upvotes: 3