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 many prompts are available in a UNIX system?
A file has multiple records each having three 30-bit long fields(field1,field2,field3).There is also a lookup file,LOOK_UP.dat.Now, we need to consider only the last ten digits of field1 and lookup the file LOOK_UP.dat. If there a match then field2 and field3 should replaced with corresponding data from the lookup file. otherwise that particular record,for which there is no match, should be stored in a seperate file.
What are the advantages of shell script?
What is shell and terminal?
How do I run a .sh file?
1.Write a script, which converts a number from binary to hexadecimal format or vice versa.
How to get the first line from a file using just the terminal?
What is the use of break command?
I have 2 files and I want to print the records which are common to both.
What is meant by $1 in shell script?
why did you apply to shell
How to print all the arguments provided to the script?