I want to get multiple reg-ex from one file. I made a for loop for that. Each reg-ex has 2 occurrences in the file. I already used grep -n to get the line-number of the two lines in which my reg-ex are located. See example: cat ../stdout_info/HTSeqQAllBAMsamples.o277329 | grep -n Sample_10Y_W34
cat ../stdout_info/HTSeqQAllBAMsamples.o277329 | grep -n Sample_10Y_W34
is:
49081:Sample_10Y_W34
73620: sample: Sample_10Y_W34 is sorted
I wrote the next line to get the regular-expressions. Every 'i' is an reg-ex. (48 i's in total)
for i in $(ls ../Datasets_qualityResults/); do echo $(basename $i); done
I want to print the lines from 49081 - 736* 14 * (always minus the last 6 lines) to a file called 'results_Sample_10Y_34.txt'.
I worked on this quite a long time, with sed and grep, but it doesn't work. Can anyone help me?
If I understand the question correct, you need to say:
sed -n '/Sample_10Y_W34/,/Sample_10Y_W34/p' filename | head -n -6 > outputfile
The sed
command would print the lines between the patterns and head
would remove the last 6 lines of the output and the result would be redirected to the file outputfile
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.