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

Hello all, This is my assignment on shell scripting, can anyone help me regarding this ? Create a shell script which connects to the database In second shell script include the first script for the DB connection Create a table (PRADEEP_DATA) with 2 columns (name, value) In Third shell script include the first script for the DB connection And insert/delete the values from the Table, by accepting input from the user This functionality should be a menu driven Program: 1) Insert to the database a. Name b. value 2)Delete from the database a.Name b.value Exception handling needs to be taken care.

0 Answers   Cap Gemini, Wipro,


I have 2 files and I want to print the records which are common to both.

0 Answers  


What is shell scripting?

0 Answers  


What is $1 in shell scripting?

0 Answers  


What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?

0 Answers  






How to write a function?

0 Answers  


Create a bash shell script that reads in a number from the user. If the number is 1, print out the date. If the number is 2, list the files in the current directory. If the number is 3, print out who is currently logged onto the system. If the number is anything else, print out an error message and exit. Name this script "various.sh"

4 Answers  


What is the difference between a variable and value?

7 Answers   Sun Microsystems,


What is the syntax of while loop in shell scripting?

0 Answers  


What is shell and shell script?

0 Answers  


What is console line?

0 Answers  


What are zombie processes?

0 Answers  


Categories