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 / 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 / abhishek

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

Is This Answer Correct ?    2 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

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

What are the different methods available to run a shell script?

2 Answers  


what is the difference between writing code in shell and editor?

1 Answers  


What does $# stand for?

3 Answers   IBM,


What are environment variables?

2 Answers  


How to replace following lines, catch (DAOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } catch (BOException e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw e; } catch (Exception e) { objLogger.error(this.getClass () + "addUpdateIssues() " + e); throw new BOException(5122); } Needs to be changed in to, catch (DAOException e) { AppException.handleException (null, null, e, null, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); } catch (BOException e) { AppException.handleException (null, null, null, e, null, null, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 0); } catch (Exception e) { AppException.handleException (null, null, null, null, null, e, "BOException", this.getClass() + "addUpdateIssues() ", null, null, null, null, null, null, null, null, 5122); }

0 Answers   Wipro,






What is egrep?

2 Answers  


What is the syntax of "expr" command?

2 Answers  


How to rename all the files in a folder having specific extension? Example: I have some files with extension (.txt) in a folder name 'Test'. I have to rename all the .txt files in a test and its subdirectories to .my extension.

15 Answers   Interra IT,


how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com

0 Answers  


What is the use of "test" command?

2 Answers  


How to add some content in any file at some desired location without using VI or some other editor in UNIX

2 Answers  


wats the she bang statment with syntax?

3 Answers  






Categories