Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
Delete single character rows in a text file

I have a text file with about 8 million rows in it. I need to remove all the rows with a single character in them. For example

This is 
the 
text file 
I 
wrote

I want to remove the entire line that has the pronoun "I" on it. Bonus points to the one who can do this on the linux command line.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Here is a try:

awk 'length>1' file

and if you do not want to delete blank lines (with zero characters)

awk 'length!=1' file

And if you have spaces on the lines (that you do not want to count as characters):

awk '{gsub(/[[:space:]]/,"")}length!=1' file
over 4 years ago · Santiago Trujillo Report

0

sed can do that as well:

sed '/^.$/d' inputFile

To store the output in a new file:

sed '/^.$/d' inputFile > outputFile

or for in-file editing:

sed -i '/^.$/d' inputFile
over 4 years ago · Santiago Trujillo Report

0

All you need is:

grep '..' file

unless you want to keep empty lines as well in which case it'd be:

grep -v '^.$' file
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!