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 / ganeswar bojanapu
Here is simply command
sed -n '50~50'p filename
| Is This Answer Correct ? | 4 Yes | 0 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 |
What is shell and shell script?
What does .sh file contain?
How do I run a .sh file?
What language is bash written in?
what are special characters and explain how does text varies by the usage of single quotes,double quotes and back quotes?
How will you copy a file from one machine to other?
How to write an Auto scripting for deleting old files using shell script and made a cron job to run on daily basis
wats the deinitions for shell utility and filter?
What is shell and terminal?
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
What are the additional egrep symbols?
What does $@ mean bash?