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 do you write sql queries using shell script for eg:- we have databae table like EMPNO,ENAME,SAL,DEPTNO columns in EMP table how you display EMPNO,SAL FIELDS from emp in SHELL SCRIPT please explain with an example
How can I Debug a shell scripts and Perl scripting?? or How do you debug a shell scripting and perl scripting ( at the compile time error or run time error) in Unix environment ?
What is the meaning of $1 in shell script?
How to add some content in any file at some desired location without using VI or some other editor in UNIX
What is k shell?
what are special characters and explain how does text varies by the usage of single quotes,double quotes and back quotes?
How do I run a .sh file?
What will happen to my current process when I execute a command using exec?
How do you create a shortcut in linux?
What is the command to find out today's date?
What is awk in shell script?
Is shell scripting difficult?