Limit reoccurrance of characters in lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Limit reoccurrance of characters in lines
# 1  
Old 05-28-2012
Limit reoccurrance of characters in lines

Hey guys and gals,

Working on a script to limit the reoccurrance of characters in a line.
Code:
sed "/\(.\).*\1/d" -i file.txt
sed "/\(.\).*\1.*\1/d" -i file.txt
sed "/\(.\).*\1.*\1.*1/d" -i file.txt
..

To limit character reoccurance with 1x, 2x, 3x etc.

However I would like to be able to put the 1x, 2x, 3x in the script as a variable, but cant seem to figure out how that is best done..

So basic idea in script would be something along the lines of ;
Code:
 
#!/bin/bash 
echo "enter filename to read from :" 
read in_file
echo "enter filename to write to :"
read out_file
echo "number of reocurring characters to allow :"
read numb_char
#
sed "/\(.\).*\1.*\1.*1/d" $in_file > $out_file

So wondering how to be able to have the .*\1 sequences done with the $numb_char variable...



Any pointers ?
# 2  
Old 05-28-2012
Try:
Code:
n=2
sed  "/\(.\)\(.*\1\)\{$n,\}/d" file.txt

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 05-28-2012
That looks like it does it !

Thanks a lot for the help and now I have a better idea on
how such things are accomplished.

Thanks again, have always gotten awesome help here Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH logging to file, limit lines

BASH Gurus: Anyone know how to append continuous output command appending to a file, but limit that file to no more than 20 lines? The program I have running is simply monitoring my UDP port 53 for incoming packets endlessly. I just need to keep this file from going over 20 lines. Once the file... (3 Replies)
Discussion started by: scorpius2k1
3 Replies

2. Shell Programming and Scripting

Limit the number of characters in bash output

Hi, I need some help with this: I'm making a script which does a couple of things with image files. The script is supposed to echo the number of each image it is processing like this: Processing image1.jpgThe problem is with images with very long filenames, so I want to know how to limit the... (5 Replies)
Discussion started by: Shadow_Reaper
5 Replies

3. UNIX for Advanced & Expert Users

Limit on amount of lines less can handle

Is there a limit on the amount of lines less can handle? I grepped for something that is pretty common in my files so I tried to filter it through less so it was easier to look at. So I then used a redirect ">" to create a file. It created a file that was 103K long. So that makes me think there is... (6 Replies)
Discussion started by: cokedude
6 Replies

4. Shell Programming and Scripting

Reading from a file with limit number of lines

Hi, I am trying to pull data from a txt file which has 51 lines Example AK AR AL AZ CA CO CT Now i want to send above data as input to script but i want to run them twice at a time in a nohup like nohup Script_name AK & (3 Replies)
Discussion started by: krux_rap
3 Replies

5. UNIX for Dummies Questions & Answers

Limit the number of characters in a bash output

I have a script that outputs the weather on two lines. If possibly I would like to set a character limit on them Currently it outputs something like but I would like to limit the lines so appends an ellipsis if nescessary: This is the script #! /bin/bash curl -s --connect-timeout... (2 Replies)
Discussion started by: Light_
2 Replies

6. Shell Programming and Scripting

Limit on Number of characters in a line - Vi editor

In the vi editor, there seems to be some limit on the number of characters could be allowed in single line. I tried a line with characters up to 1880. It worked. But when i tried with something of 5000 characters, it doesnt work. Any suggestions. Thanks in advance! (2 Replies)
Discussion started by: nram_krishna@ya
2 Replies

7. HP-UX

cron 80 characters limit

Hello everyone. I am trying to set up a monitor based on a "top" command statistic as follows: top -bc -n1 > output.txt I've put this command into a small script which is called by a cron... but there is something strange happening: the cron is limiting the output to output.txt to 80... (3 Replies)
Discussion started by: MartinF
3 Replies

8. AIX

Is the Length of User ID for AIX Limit to 8 Characters?

Hi, I'm using AIX version 5.3 currently. I'm trying to create a user id, e.g. andyleong, which the system prompted the length is too long. 1. I would like to know is that the length of user id is limited to maximum 8 characters for AIX. 2. Is it apply to all versions of AIX? If no... (2 Replies)
Discussion started by: meihua_t
2 Replies

9. Shell Programming and Scripting

Limit of number of lines for awk and sed.

Hi, I'm using awk and sed to extract some data out from a text file. The text file consists of data over a million (prolly millions) of lines. Question: Is there a limit of number of lines for awk and sed? Thanks in advance. (2 Replies)
Discussion started by: 60doses
2 Replies

10. Shell Programming and Scripting

Limit of no of characters PER LINE in a unix file

Hi , Whats the limit of characters PER LINE in a unix file , allowed for editing..sort , cut , sed , awk etc (5 Replies)
Discussion started by: mohapatra
5 Replies
Login or Register to Ask a Question