Unix Scripting Compare Integers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix Scripting Compare Integers
# 1  
Old 01-14-2009
Unix Scripting Compare Integers

I have a file with the following:

87565
82155
102656
151
162


I want to write korn shell script that will read each line in a loop and remove any number that has less than 5 digits, e.g., 151 and 152.

thank you,

KeokiSmilie
# 2  
Old 01-14-2009
Comparing string lengths


Your title is incorrect. You do not want to compare integers, you want to compare string lengths.

Code:
while read n
do
  [ ${#n} -ge 5 ] && printf "%s\n" "$n"
done < FILE

For a large file, it will be faster with awk, sed or even grep:

Code:
awk 'length >= 5' FILE

awk '/...../' FILE

sed -n '/...../p' FILE

grep '.....' FILE


Last edited by cfajohnson; 01-14-2009 at 10:29 PM..
# 3  
Old 01-14-2009
Try...
Code:
grep ..... file

# 4  
Old 01-15-2009
Thank you very much, your code does exactly what I want.

I guess was I not articulating my problem corretly so I had no luck searching the newsgroups.
# 5  
Old 01-15-2009
Yeah, ..... will work for 5 digits/letters/zebras.. but just in case you want to get them from a file that has letters or other stuff..

egrep "[0-9]{5,}" FILE

I know it looks different, but I like to search for *exactly* what I am searching for, maybe I am just weird. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh scripting SSH to Compare File Sizes

Hello, I currently have very little experience with Shell scripting and trying to create a script for the purpose of collecting the size of a couple sizes on 4 different Hosts. The Idea is to collected the information from the files in which the script is kicked off on, store the values into... (17 Replies)
Discussion started by: Abstract3000
17 Replies

2. UNIX for Dummies Questions & Answers

How to compare to values returned from sql in shell scripting?

hey i am using this code to connect to sql , store the value in variable and then compare it with another variable after some time by executing the same query but the desired result is not coming #!/bin/bash val=$(sqlplus -s rte/rted2@rel76d2 <<ENDOFSQL set heading off set feedback off... (11 Replies)
Discussion started by: ramsavi
11 Replies

3. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

4. Shell Programming and Scripting

Compare files using Unix scripting

I have a file containing the below data obtained after running a diff command > abc 10 < abc 15 > xyz 02 <xyz 05 ..... Does anyone know how i can obtain output like : previous value of abc is 10 and present value is 15 similarly for all the comparisons in the text file (10 Replies)
Discussion started by: amithpatrick1
10 Replies

5. Shell Programming and Scripting

Compare two files using shell scripting

Hi, I need to compare two files using shell scripting. Say like: File1 AAAAAAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBBBBBBB CCCCCCCCCCCCCCCCCCCCCCCCC eeeeeeeeeeeeeeeeeeeeeeeee DDDDDDDDDDDDDDDDDDDDDDDDDDDD File2 BBBBBBBBBBBBBBBBBBBBB DDDDDDDDDDDDDDDDDDDDDDDDDDDD AAAAAAAAAAAAAAAAAAAA ... (6 Replies)
Discussion started by: roshParab
6 Replies

6. Shell Programming and Scripting

Shell Scripting: Compare pattern in two files and merge the o/p in one.

one.txt ONS.1287677000.820.log 20Oct2010 ONS.1287677000.123.log 21Oct2010 ONS.1287677000.456.log 22Oct2010 two.txt ONS.1287677000.820.log:V AC CC EN ONS.1287677000.123.log:V AC CC EN ONS.1287677000.820.log:V AC CC EN In file two.txt i have to look for pattern which column one... (17 Replies)
Discussion started by: saluja.deepak
17 Replies

7. Shell Programming and Scripting

Shell scripting for this sequence to compare

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample.... (4 Replies)
Discussion started by: hravisankar
4 Replies

8. Shell Programming and Scripting

Using Bash scripting to compare arrays looking for matches

I have two arrays I need to compare against a third, looking for matches, not differences. I think I'm going to have to convert the arrays to files and grep them, but I'm not too sure if there's a tool to enable me to matches specifically, instead of differences. Thanks in advance! Karl (9 Replies)
Discussion started by: karlp
9 Replies

9. Shell Programming and Scripting

How to compare a command line parameter with -- in shell scripting

Hi, I need to check if a parameter provided at the command line is equal to --.How can i do that ? Please help me. Thanks and Regards, Padmini (4 Replies)
Discussion started by: padmisri
4 Replies

10. Shell Programming and Scripting

Bash scripting to compare N number of files located in two directories

I want to compare "N" (around 2000+) number of huge files located in a directory A against "N" files located in a different directory using Bash scripting. Please help me with any scripts available. Thanks. (2 Replies)
Discussion started by: Sangtha
2 Replies
Login or Register to Ask a Question