Filter all the lines with minimum specified length of words of a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter all the lines with minimum specified length of words of a text file
# 1  
Old 06-10-2015
Filter all the lines with minimum specified length of words of a text file

Hi

Can someone tell me which script will work best (in terms of speed and simplicity to write and run) for a large text file to filter all the lines with a minimum specified length of words ? A sample script with be definitely of great help !!! Thanks in advance. Smilie
# 2  
Old 06-10-2015
A CLEAR statement of what you are trying to do, a sample input file (in CODE tags), and the output you want to get from that sample input file (in CODE tags) would make it a LOT easier to help you. Without that, I could suggest cat and cp as great starting points for your script.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 06-11-2015
Filter all the lines with minimum specified length of words of a text file

The content of the sample file to be filtered is :
=============================

Code:
This is a test file.
This is
This
That 
That is 
I
You
That is a sample.

============================
And the sample output should look like as given below if I filter sentences more than or equal to 2 (two) words in a line.

Code:
This is a test file.
This is
That is 
That is a sample.


Last edited by Don Cragun; 06-11-2015 at 10:46 PM.. Reason: Change HTML tags to CODE tags.
# 4  
Old 06-11-2015
Code:
awk 'NF >= 2' filename

These 2 Users Gave Thanks to Aia For This Post:
# 5  
Old 06-12-2015
Quote:
Originally Posted by my_Perl
Hi

Can someone tell me which script will work best (in terms of speed and simplicity to write and run) for a large text file to filter all the lines with a minimum specified length of words ? A sample script with be definitely of great help !!! Thanks in advance. Smilie
length of words => number of words
But, as one can see, one example input and an expected output, and the matter is clear!
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File

Hi All It's me again with another huge txt files. :confused: What I have: - I have 33 huge txt files in a folder. - I have thousands of line in this txt file which contain many the letter "x" in them. - Some of them have more than one "x" character in the line. What I want to achieve:... (8 Replies)
Discussion started by: Nexeu
8 Replies

2. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

3. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

4. Shell Programming and Scripting

Filter file by length, looking only at lines that don't begin with ">"

I have a file that stores data in pairs of lines, following this format: line 1: header (preceded by ">") line 2: sequence Example.txt: >seq1 name GATTGATGTTTGAGTTTTGGTTTTT >seq2 name TTTTCTTC I want to filter out the sequences and corresponding headers for all sequences that are less... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

5. Shell Programming and Scripting

Filter (by max length) only lines not matching regex

I have a large file of many pairs of sequences and their headers, which always begin with '>' I'm looking for help on how to retain only sequences (and their headers) below a certain length. So if min length was 10, output would be I can filter by length, but I'm not sure how to exclude... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. UNIX for Dummies Questions & Answers

Display all the words whose length is equal to the longest word in the text

Hi Guys, I was going some trial and error to see if I can find the longest word in a text. I was using Pipes because they are easier to use in this case. I was stuck on this for a while so I thought I'll get some help with it. I tried this code to separate all the words in a text in... (4 Replies)
Discussion started by: bawse.c
4 Replies

7. Shell Programming and Scripting

Shell script to read lines in a text file and filter user data

hi all, I have this file with some user data. example: $cat myfile.txt FName|LName|Gender|Company|Branch|Bday|Salary|Age aaaa|bbbb|male|cccc|dddd|19900814|15000|20| eeee|asdg|male|gggg|ksgu|19911216||| aara|bdbm|male|kkkk|acke|19931018||23| asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Discussion started by: srimal
4 Replies

8. Shell Programming and Scripting

remove strings of lowercase characters (with minimum length requirement)

Hi all, I want to delete all lowercase characters from my file, but only strings of length 7 and more. For example, how can I go from: JHGEFigeIGDUIirfyfiyhgfoiyfKJHGuioyrDHG To: JHGEFigeIGDUIKJHGuioyrDHG There should be a trick to add to sed 's///g', but I can't figure it out.... (2 Replies)
Discussion started by: elbuzzo
2 Replies

9. HP-UX

minimum password length

Dear frnds, how i can make the password 5chs minimum length in hp-ux 11i ? pls help regards (3 Replies)
Discussion started by: jestinabel
3 Replies
Login or Register to Ask a Question