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



Answer / ramesh jp

awk 'NR % 50 == 0' print

Is This Answer Correct ?    9 Yes 1 No

Answer / kavita

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

Is This Answer Correct ?    6 Yes 2 No

Answer / ganeswar bojanapu

Here is simply command

sed -n '50~50'p filename

Is This Answer Correct ?    4 Yes 0 No




Answer / sarthak

shivu,

your ans is wrong

Is This Answer Correct ?    3 Yes 0 No

Answer / vivek

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

Is This Answer Correct ?    2 Yes 2 No

Answer / abhishek

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

Is This Answer Correct ?    2 Yes 3 No

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

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

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

If one dont know how to create a script then how he/she can use the QTP?

1 Answers  


I want to upload a file to remote server through ftp daily.Can anyone suggest how to make a shell script for that.I hv credentials for that ftp

1 Answers  


c program which accept one argument as a directory name and prints all the file name along with its inode number and total count of the file in directory

1 Answers  


How to customise the other shell?

2 Answers   Quest,


write a shell script to emulate the Id command of PRIMOS which lists files and directories. It list files first with a header FILES and then directories with a header DIRECTORIES. This command has several options. The main ones are. -file select files only -dir select directories only -reverse sort in reverse order -no_header put no header on the output -brief output the header only -size display the size of each file -help display Id´s syntax and options.

0 Answers  






Write a shell script to check whether a number is Armstrong number or not?

1 Answers   Flipkart,


what do u mean by $#,$* in unix programming?

5 Answers   TCS, Convergys,


how to create purchase order

2 Answers  


Where cron file kept?

2 Answers   Tech Mahindra,


write a non recursive shell script that accepts any number of arguments and prints them in the reverse order

3 Answers  


what are special characters and explain how does text varies by the usage of single quotes,double quotes and back quotes?

1 Answers  


HOW TO CREATE 10 USERS IN UNIX(HP-UX) USING SHELL SHELL SCRIPT?

3 Answers   Patni,






Categories