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 |
How would you print just the 25th line in a file using smallest shell script?
What is a shell script? Can you name some of its advantages?
Hi, I want to practise Unix korn shell scripting which i learnt 2 yr bfr. plz suggest software i can use to practise.
What is scripting used for?
What is the use of script interpreter in shell scripting?
What is a program shell?
What are the Different types of shells?
What shell is bin sh?
How will you copy a file from one machine to other?
What is the best scripting language?
What is @echo off?
What is computer cli?