Checking File record equal to multiple of 70 or nearest number to multiple of 70


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking File record equal to multiple of 70 or nearest number to multiple of 70
# 1  
Old 04-26-2016
Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello,

I have a file with below content - Example
Code:
3
6
69
139
210
345
395
418
490
492

I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70
Code:
69
139
210
345
418
490

I tried using awk but doesn't succeed in getting result. Please try and let me know the way if we could achieve the result in unix.

Thanks,
Mannu
# 2  
Old 04-26-2016
I'm not getting your approach to create the output - could you post your existing code?
Otherwise your definition of nearest (when number modulo 70 is not equal to zero) would help.
# 3  
Old 04-26-2016
I think I see the pattern, but I don't understand why the desired output doesn't include the final line:
Code:
492

If you wanted that final line as well as the output you said you wanted, you could try something like:
Code:
awk '
NR == 1 || $1 > m {
	if(NR > 1)
		print v
	m = int(($1 + 69)/70) * 70
}
{	v = $1
}
END {	print v
}' file

which, if file contains your sample data, produces the output:
Code:
69
139
210
345
418
490
492

This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 04-26-2016
try also:
Code:
awk '
{
l=$1 % 70; if (! l ) c[NR]=d[NR]=1;
n[NR]=$1; m[NR]=l
}
END {
   c[0]=d[0]=c[NR+1]=d[NR+1]=70;
   for (i=0; i<NR; i++) if (m[i+1] <= m[i]) c[i]=1
   for (i=NR; i>1; i--) if (m[i-1] <= m[i]) d[i]=1
   for (i=1; i<=NR; i++) if (c[i] && d[i]) print n[i]
}
' infile

This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 04-27-2016
Try also
Code:
awk '{T[int(($1-1)/70)] = $1} END {for (t in T) print T[t]}' file
69
139
210
345
418
490
492

These 2 Users Gave Thanks to RudiC For This Post:
# 6  
Old 04-27-2016
Thank you Don Cragun , rdrtx1 and RudiC.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

2. UNIX for Dummies Questions & Answers

Display latest record from file based on multiple columns combination

I have requirement to print latest record from file based on multiple columns combination. EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/16/2015 100004 03/16/2015 100005 001 EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 140003 03/18/2015 140004 001 EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 220006... (1 Reply)
Discussion started by: tmalik79
1 Replies

3. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

4. Shell Programming and Scripting

Awk: File Checking Issues with 9 multiple file

Hi, I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size. so further i am unable to consolidate the files based on following code 1 awk -F, -v ptime="201407" 'FNR==1... (3 Replies)
Discussion started by: siramitsharma
3 Replies

5. Shell Programming and Scripting

Record count checking for multiple files through for-loop

Hi Friends, I wrote one shell script to check the record count in two files and that will send us the notification activity if found zero record count. What i did is I created for loop and checking the count for both of the files but what is happening is for first file has data then it's... (13 Replies)
Discussion started by: victory
13 Replies

6. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

7. Shell Programming and Scripting

Compare multiple files with multiple number of columns

Hi, input file1 abcd 123 198 xyz1:0909090-0909091 ghij 234 999 xyz2:987654:987655 kilo 7890 7990 xyz3:12345-12357 prem 9 112 xyz5:97-1134 input file2 abcd 123 198 xyz1:0909090-0909091 -9.122 0 abed 88 98 xyz1:98989-090808 -1.234 1.345 ghij 234 999 xyz2:987654:987655 -10.87090909 5... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

8. Shell Programming and Scripting

Make multiple files of equal length

I have 150 files with 4 columns each but variable row lengths that I need to combine by column. I do not have any common column. I want to use "paste " command in unix to do it but before that I have to get all my files to be of equal length. Is there a way using awk or sed to fill up n no. of... (7 Replies)
Discussion started by: manishabh
7 Replies

9. Shell Programming and Scripting

Multiple file existence and checking file size

I want to check the files in particular directory are more that 0 Bytes i.e, Non zero byte file. The script should print a msg if all the files in that directory are empty( 0 Byte). (2 Replies)
Discussion started by: lathish
2 Replies

10. Shell Programming and Scripting

Checking Multiple file existence

Hi, I want to check multiple files exist or not in a single if statement in korn Shell:confused:. Please help me Thanks (1 Reply)
Discussion started by: lathish
1 Replies
Login or Register to Ask a Question