Problem with grep on multiple files and not getting desired output Announcing the arrival of...
What does this icon in iOS Stardew Valley mean?
Bete Noir -- no dairy
The logistics of corpse disposal
How does the particle を relate to the verb 行く in the structure「A を + B に行く」?
How to answer "Have you ever been terminated?"
How do pianists reach extremely loud dynamics?
What causes the vertical darker bands in my photo?
Why do people hide their license plates in the EU?
Coloring maths inside a tcolorbox
How to call a function with default parameter through a pointer to function that is the return of another function?
What exactly is a "Meth" in Altered Carbon?
Output the ŋarâþ crîþ alphabet song without using (m)any letters
Using et al. for a last / senior author rather than for a first author
Is it true that "carbohydrates are of no use for the basal metabolic need"?
What is the role of the transistor and diode in a soft start circuit?
How do I stop a creek from eroding my steep embankment?
How to bypass password on Windows XP account?
Error "illegal generic type for instanceof" when using local classes
How to find out what spells would be useless to a blind NPC spellcaster?
Why didn't this character "real die" when they blew their stack out in Altered Carbon?
How can I make names more distinctive without making them longer?
What is Wonderstone and are there any references to it pre-1982?
How widely used is the term Treppenwitz? Is it something that most Germans know?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Problem with grep on multiple files and not getting desired output
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionOutput multiple files from a single grep?Why is my Netstat not returning the desired output and just getting hung up?Formatting the output of grep when matching on multiple filesNot getting grep with a variableProblem with grep -ogrep: problem with regular expressionGrep multiple files and output to multiple files in a single commandgrep dynamically multiple files with customized outputWhy does head; tail on a large file sometimes take a long time and sometimes not?grep and tail multiple files
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do this for chr(1to 22 and then chrX and chrY) , am not using any loop, I did it invidually , but if you see that I want the header to be intact for each of my output. If I execute individually I get the header in the output but if am running but if I run the script for all the 8 files together which is like 8*24 commands in a script one after another, the output does not have any header. Can you tell me why is this happening?
#!/bin/sh
#
#$ -N DOC_gatk_chr
#$ -cwd
#$ -e err_DOC_gatk_chr.txt
#$ -o out_DOC_gatk_chr.txt
#$ -S /bin/sh
#$ -M vivek.das@ieo.eu
#$ -m bea
#$ -l h_vmem=25G
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr1" > S_313_IPS_S7995.chr1.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr2" > S_313_IPS_S7995.chr2.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr3" > S_313_IPS_S7995.chr3.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr4" > S_313_IPS_S7995.chr4.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr5" > S_313_IPS_S7995.chr5.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr6" > S_313_IPS_S7995.chr6.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr7" > S_313_IPS_S7995.chr7.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr8" > S_313_IPS_S7995.chr8.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr9" > S_313_IPS_S7995.chr9.coverage
Am running it as a job with qsub so the structure of the script looks like above. It works if I execute the commands individually but if I run them like this , the header does not get printed in the output file, the ';' is not recognized it seems. I tried to ran it with both qsub filename.sh and sh filename.sh. I found that with sh filename.sh the header gets printed in the console. So definitely the command before';' semi-colon is not being written in the file. How can I get rid of this problem.
Desired output:
Target total_coverage average_coverage IPS_S7995_total_cvg IPS_S7995_mean_cvg IPS_S7995_granular_Q1 IPS_S7995_granular_median IPS_S7995_granular_Q3 IPS_S7995_%_above_15
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
But output am getting is below without the header
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
linux grep head header-file more
add a comment |
I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do this for chr(1to 22 and then chrX and chrY) , am not using any loop, I did it invidually , but if you see that I want the header to be intact for each of my output. If I execute individually I get the header in the output but if am running but if I run the script for all the 8 files together which is like 8*24 commands in a script one after another, the output does not have any header. Can you tell me why is this happening?
#!/bin/sh
#
#$ -N DOC_gatk_chr
#$ -cwd
#$ -e err_DOC_gatk_chr.txt
#$ -o out_DOC_gatk_chr.txt
#$ -S /bin/sh
#$ -M vivek.das@ieo.eu
#$ -m bea
#$ -l h_vmem=25G
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr1" > S_313_IPS_S7995.chr1.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr2" > S_313_IPS_S7995.chr2.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr3" > S_313_IPS_S7995.chr3.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr4" > S_313_IPS_S7995.chr4.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr5" > S_313_IPS_S7995.chr5.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr6" > S_313_IPS_S7995.chr6.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr7" > S_313_IPS_S7995.chr7.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr8" > S_313_IPS_S7995.chr8.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr9" > S_313_IPS_S7995.chr9.coverage
Am running it as a job with qsub so the structure of the script looks like above. It works if I execute the commands individually but if I run them like this , the header does not get printed in the output file, the ';' is not recognized it seems. I tried to ran it with both qsub filename.sh and sh filename.sh. I found that with sh filename.sh the header gets printed in the console. So definitely the command before';' semi-colon is not being written in the file. How can I get rid of this problem.
Desired output:
Target total_coverage average_coverage IPS_S7995_total_cvg IPS_S7995_mean_cvg IPS_S7995_granular_Q1 IPS_S7995_granular_median IPS_S7995_granular_Q3 IPS_S7995_%_above_15
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
But output am getting is below without the header
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
linux grep head header-file more
1
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
Also consider simplifying it by removingmore
and giving the files as arguments directly tohead
andgrep
.
– peterph
Jan 27 '15 at 11:19
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43
add a comment |
I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do this for chr(1to 22 and then chrX and chrY) , am not using any loop, I did it invidually , but if you see that I want the header to be intact for each of my output. If I execute individually I get the header in the output but if am running but if I run the script for all the 8 files together which is like 8*24 commands in a script one after another, the output does not have any header. Can you tell me why is this happening?
#!/bin/sh
#
#$ -N DOC_gatk_chr
#$ -cwd
#$ -e err_DOC_gatk_chr.txt
#$ -o out_DOC_gatk_chr.txt
#$ -S /bin/sh
#$ -M vivek.das@ieo.eu
#$ -m bea
#$ -l h_vmem=25G
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr1" > S_313_IPS_S7995.chr1.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr2" > S_313_IPS_S7995.chr2.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr3" > S_313_IPS_S7995.chr3.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr4" > S_313_IPS_S7995.chr4.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr5" > S_313_IPS_S7995.chr5.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr6" > S_313_IPS_S7995.chr6.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr7" > S_313_IPS_S7995.chr7.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr8" > S_313_IPS_S7995.chr8.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr9" > S_313_IPS_S7995.chr9.coverage
Am running it as a job with qsub so the structure of the script looks like above. It works if I execute the commands individually but if I run them like this , the header does not get printed in the output file, the ';' is not recognized it seems. I tried to ran it with both qsub filename.sh and sh filename.sh. I found that with sh filename.sh the header gets printed in the console. So definitely the command before';' semi-colon is not being written in the file. How can I get rid of this problem.
Desired output:
Target total_coverage average_coverage IPS_S7995_total_cvg IPS_S7995_mean_cvg IPS_S7995_granular_Q1 IPS_S7995_granular_median IPS_S7995_granular_Q3 IPS_S7995_%_above_15
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
But output am getting is below without the header
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
linux grep head header-file more
I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do this for chr(1to 22 and then chrX and chrY) , am not using any loop, I did it invidually , but if you see that I want the header to be intact for each of my output. If I execute individually I get the header in the output but if am running but if I run the script for all the 8 files together which is like 8*24 commands in a script one after another, the output does not have any header. Can you tell me why is this happening?
#!/bin/sh
#
#$ -N DOC_gatk_chr
#$ -cwd
#$ -e err_DOC_gatk_chr.txt
#$ -o out_DOC_gatk_chr.txt
#$ -S /bin/sh
#$ -M vivek.das@ieo.eu
#$ -m bea
#$ -l h_vmem=25G
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr1" > S_313_IPS_S7995.chr1.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr2" > S_313_IPS_S7995.chr2.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr3" > S_313_IPS_S7995.chr3.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr4" > S_313_IPS_S7995.chr4.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr5" > S_313_IPS_S7995.chr5.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr6" > S_313_IPS_S7995.chr6.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr7" > S_313_IPS_S7995.chr7.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr8" > S_313_IPS_S7995.chr8.coverage
more S_313_IPS_S7995.coverage.sample_interval_summary | head -n1; more S_313_IPS_S7995.coverage.sample_interval_summary | grep "chr9" > S_313_IPS_S7995.chr9.coverage
Am running it as a job with qsub so the structure of the script looks like above. It works if I execute the commands individually but if I run them like this , the header does not get printed in the output file, the ';' is not recognized it seems. I tried to ran it with both qsub filename.sh and sh filename.sh. I found that with sh filename.sh the header gets printed in the console. So definitely the command before';' semi-colon is not being written in the file. How can I get rid of this problem.
Desired output:
Target total_coverage average_coverage IPS_S7995_total_cvg IPS_S7995_mean_cvg IPS_S7995_granular_Q1 IPS_S7995_granular_median IPS_S7995_granular_Q3 IPS_S7995_%_above_15
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
But output am getting is below without the header
chr2:41460-41683 14271 63.71 14271 63.71 56 67 79 100.0
chr2:45338-46352 123888 122.06 123888 122.06 79 123 147 94.6
chr2:218731-218983 11653 46.06 11653 46.06 36 50 55 100.0
chr2:224825-225012 12319 65.53 12319 65.53 57 68 76 100.0
chr2:229912-230090 20983 117.22 20983 117.22 93 120 147 100.0
chr2:230947-231137 22386 117.20 22386 117.20 100 120 139 100.0
chr2:233074-233258 11710 63.30 11710 63.30 54 66 73 100.0
chr2:234086-234300 22952 106.75 22952 106.75 91 113 126 100.0
chr2:242747-242922 20496 116.45 20496 116.45 93 124 142 100.0
chr2:243469-243671 27074 133.37 27074 133.37 126 138 148 100.0
linux grep head header-file more
linux grep head header-file more
edited 5 hours ago
Rui F Ribeiro
42.1k1484142
42.1k1484142
asked Jan 27 '15 at 11:07
vchris_ngsvchris_ngs
1084
1084
1
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
Also consider simplifying it by removingmore
and giving the files as arguments directly tohead
andgrep
.
– peterph
Jan 27 '15 at 11:19
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43
add a comment |
1
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
Also consider simplifying it by removingmore
and giving the files as arguments directly tohead
andgrep
.
– peterph
Jan 27 '15 at 11:19
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43
1
1
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
Also consider simplifying it by removing
more
and giving the files as arguments directly to head
and grep
.– peterph
Jan 27 '15 at 11:19
Also consider simplifying it by removing
more
and giving the files as arguments directly to head
and grep
.– peterph
Jan 27 '15 at 11:19
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43
add a comment |
1 Answer
1
active
oldest
votes
You need something like this:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
or
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
The problem is that the redirection affects only one command. In order to get the output of head
and grep
in the redirection they have to be grouped. But awk
is probably the better choice here.
I used the previous one even that one works out.{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work becausehead
reads more than the first line. But an input redirection is seekable sohead
resets to the positiongrep
should see. It does not work withcat file | { head ...
. But it would be safe to use the shell bulitinread
:{ IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f181318%2fproblem-with-grep-on-multiple-files-and-not-getting-desired-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need something like this:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
or
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
The problem is that the redirection affects only one command. In order to get the output of head
and grep
in the redirection they have to be grouped. But awk
is probably the better choice here.
I used the previous one even that one works out.{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work becausehead
reads more than the first line. But an input redirection is seekable sohead
resets to the positiongrep
should see. It does not work withcat file | { head ...
. But it would be safe to use the shell bulitinread
:{ IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
add a comment |
You need something like this:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
or
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
The problem is that the redirection affects only one command. In order to get the output of head
and grep
in the redirection they have to be grouped. But awk
is probably the better choice here.
I used the previous one even that one works out.{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work becausehead
reads more than the first line. But an input redirection is seekable sohead
resets to the positiongrep
should see. It does not work withcat file | { head ...
. But it would be safe to use the shell bulitinread
:{ IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
add a comment |
You need something like this:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
or
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
The problem is that the redirection affects only one command. In order to get the output of head
and grep
in the redirection they have to be grouped. But awk
is probably the better choice here.
You need something like this:
{ head -n1 S_313_IPS_S7995.coverage.sample_interval_summary;
grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage
or
awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage
The problem is that the redirection affects only one command. In order to get the output of head
and grep
in the redirection they have to be grouped. But awk
is probably the better choice here.
edited Jan 27 '15 at 12:04
answered Jan 27 '15 at 11:55
Hauke LagingHauke Laging
57.9k1288137
57.9k1288137
I used the previous one even that one works out.{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work becausehead
reads more than the first line. But an input redirection is seekable sohead
resets to the positiongrep
should see. It does not work withcat file | { head ...
. But it would be safe to use the shell bulitinread
:{ IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
add a comment |
I used the previous one even that one works out.{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work becausehead
reads more than the first line. But an input redirection is seekable sohead
resets to the positiongrep
should see. It does not work withcat file | { head ...
. But it would be safe to use the shell bulitinread
:{ IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
I used the previous one even that one works out.
{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
I used the previous one even that one works out.
{ head -n1; grep "chr1"; } <S_333_IPS_S7997.coverage.sample_interval_summary >S_333_IPS_S7997.chr1.coverage
– vchris_ngs
Jan 27 '15 at 13:21
@vchris_ngs I was afraid that might not work because
head
reads more than the first line. But an input redirection is seekable so head
resets to the position grep
should see. It does not work with cat file | { head ...
. But it would be safe to use the shell bulitin read
: { IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
@vchris_ngs I was afraid that might not work because
head
reads more than the first line. But an input redirection is seekable so head
resets to the position grep
should see. It does not work with cat file | { head ...
. But it would be safe to use the shell bulitin read
: { IFS= read -r line; echo "$line"; grep ...;} <...
– Hauke Laging
Jan 27 '15 at 13:26
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
yes it does not work with cat but with it did work here. anyway I will keep this in mind will use awk for such actions. Thanks a lot. But yes heads work with first link this case so it worked out properly
– vchris_ngs
Jan 27 '15 at 13:35
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f181318%2fproblem-with-grep-on-multiple-files-and-not-getting-desired-output%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
"If I execute individually I get the header" What header? Why don't you show us both the output you get and the output you expect / want?
– Hauke Laging
Jan 27 '15 at 11:10
Also consider simplifying it by removing
more
and giving the files as arguments directly tohead
andgrep
.– peterph
Jan 27 '15 at 11:19
I try to do a kind of troubleshooting and I found that when I am running the command individually it is working but if I am running with qsub as a job the headers are not getting appended in the output file.
– vchris_ngs
Jan 27 '15 at 11:34
@HaukeLaging . I have already edited the question. Can you please take a look now and let me know if its clear.
– vchris_ngs
Jan 27 '15 at 11:43