How to remove lines that exceed a certain charecter count?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove lines that exceed a certain charecter count?
# 1  
Old 07-06-2015
How to remove lines that exceed a certain charecter count?

I am trying to remove lines in a variable(nidlist) that exceed a certain charecter count(in this case 7).

I am trying to incorparate the function that removes the lines that exceed 7 into this piece of code

nidlist=$(print $nidlist |tr  ';'  '\n' | sort | uniq | tr '\n' ';')

Thank You
# 2  
Old 07-06-2015
Get ideas from this example :
echo "abcdefghij;klmnop;qrstuv;wxyz" | tr ';' '\n' | sort | uniq | awk 'length()<8' | tr '\n' ';'

Last edited by tukuyomi; 07-06-2015 at 04:01 PM.. Reason: Oops for the double quote in the awk script
# 3  
Old 07-06-2015
This will give you the length of the string...unless you have a concrete example, its hard to suggest..

echo ${#string}

# 4  
Old 07-06-2015
Can do it in one awk:

nidlist=$(print $nidlist | awk '!x[$0]++&&length($0)<8'  ORS=\; RS=\;)

# 5  
Old 07-08-2015
If it's an input file, one could use egrep I suppose:-
egrep -v "........" $file

The full-stop is a single character wild-card. There are eight of them to denote a line which matches any eight characters, so seven or less is not selected to be removed.

It's a bit of a convoluted thought process, but does that offer an alternative?

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Simple question about charecter count

Hi, I have collection of letters in a column such as: AA5678 AA9873434 .. .. I am trying to find the number of charecters in each. "echo "AA5678"|wc -c 7----------------> why does it give 7 instead of 6? (6 Replies)
Discussion started by: kvosu
6 Replies

2. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

awk to remove lines where field count is greather than 1 in two fields

I am trying to remove all the lines and spaces where the count in $4 or $5 is greater than 1 (more than 1 letter). The file and the output are tab-delimited. Thank you :). file X 5811530 . G C NLGN4X 17 10544696 . GA G MYH3 9 96439004 . C ... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Remove lines that are subsets of other lines in File

Hello everyone, Although it seems easy, I've been stuck with this problem for a moment now and I can't figure out a way to get it done. My problem is the following: I have a file where each line is a sequence of IP addresses, example : (5 Replies)
Discussion started by: MisterJellyBean
5 Replies

5. Shell Programming and Scripting

Two files, remove lines from second based on lines in first

I have two files, a keepout.txt and a database.csv. They're unsorted, but could be sorted. keepout: user1 buser3 anuser19 notheruser27 database: user1,2343,"information about",field,blah,34 user2,4231,"mo info",etc,stuff,43 notheruser27,4344,"hiya",thing,more thing,423... (4 Replies)
Discussion started by: esoffron
4 Replies

6. UNIX for Dummies Questions & Answers

Want to remove all lines but not latest 50 lines from a file

Hi, I have a huge file which has Lacs of lines. File system got full. I want your guys help to suggest me a solution so that I can remove all lines from that file but not last 50,000 lines. I want solution which can remove lines from existing file so that I can have some space left with. (28 Replies)
Discussion started by: prashant2507198
28 Replies

7. UNIX for Dummies Questions & Answers

In ls -l remove total count

Hi All, When i give ls -ltr i get 'total 10' like this along with files long listing. is there any option in ls command to remove this line or do we need use head -1 command only. $ls -ltr total 45 -rw-r--r-- 1 abc g1 0 Jul 17 07:20 0 -rw-r--r-- 1 abc g1 744 May 9 12:10 a -rw-r--r--... (1 Reply)
Discussion started by: HemaV
1 Replies

8. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

9. Shell Programming and Scripting

Comapring files charecter by charecter using AWK/Shell Script

Hi... I have a requrement to compare two files. for e.g. File 1 2007/08/19 09:48:10 DH-032 $APTA1: Device AATD8029 2007/08/19 09:48:10 DH-045 $APTA1: Device AATD8029 2007/08/19 09:48:10 DH-043 $APTA1: Device AATD8029 File 2 2007-08-19 09:48:10 DH-032... (1 Reply)
Discussion started by: evvander
1 Replies

10. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies
Login or Register to Ask a Question

Featured Tech Videos