In a file , how to retrieve the lines which are the
multiples of 50 ? like 50,100,150th lines etc.

Answers were Sorted based on User's Feedback



In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / ramesh jp

awk 'NR % 50 == 0' print

Is This Answer Correct ?    10 Yes 1 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / kavita

awk 'NR % 50 ==0 {print}' filename

Is This Answer Correct ?    6 Yes 2 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / ganeswar bojanapu

Here is simply command

sed -n '50~50'p filename

Is This Answer Correct ?    4 Yes 0 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / sarthak

shivu,

your ans is wrong

Is This Answer Correct ?    3 Yes 0 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / vivek

egrep "^[0-9]*[05]0$" filename

Is This Answer Correct ?    2 Yes 2 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / abhishek

awk 'NR % 2 == 0 {print}' abc.txt

Is This Answer Correct ?    3 Yes 4 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / shivu

i=50
lines=`wc -l file | cut -d" " -f1`
while [ "$i" -le "$lines" ]
do
head -n $i file | tail -1
i=`expr $i + 50`
done


It works for anything.. :)

Is This Answer Correct ?    3 Yes 5 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / shivu

root@chandru-VirtualBox:~# egrep "^[0-9]*[0|5]0" file
50
100
150
200
250
300
350
400
450
500
501
502
503
504
505
506
507
508
509
550
600
650
700
750
800
850
900
950
1000

But the below one is
root@chandru-VirtualBox:~# egrep "^[0-9][0|5][0]" file
100
150
200
250
300
350
400
450
500
550
600
650
700
750
800
850
900
950
1000

This is also not correct. up to some extend it is ok.

Is This Answer Correct ?    1 Yes 4 No

In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc...

Answer / mohsin

egrep "^[0-9]*[0|5]0" filename

Is This Answer Correct ?    5 Yes 13 No

Post New Answer

More Shell Script Interview Questions

Print the 10th line without using tail and head command.

0 Answers  


Explain about gui scripting?

0 Answers  


How to declare functions in unix shell script?

4 Answers  


What does $$ mean in shell script?

0 Answers  


Where are cowrie shells found?

0 Answers  






Where is bash history?

0 Answers  


if i have 2 files file1 and file2.... file1 contains 2 columns like b a 11 aa 12 as 13 ad 15 ag 11 ar 13 ah 15 ak file2 contains b c 10 ds 11 at 15 gh 15 jk 13 iu 11 fg 13 yy can any 1 give me the program to display in this way? a b c aa 11 at ar 11 fg ad 13 iu ah 13 yy ag 15 gh ak 15 jk

3 Answers  


How do I save a powershell script?

0 Answers  


Explain about stdin, stdout and stderr?

0 Answers  


How will I insert a line "abcdef" at every 100th line of a file?

2 Answers  


What is shell variable?

0 Answers  


What is shell prompt?

0 Answers  


Categories