awk/sed part of filename
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.
For example,
I have multiple files:
a.fastq.gz
b.fastq.gz
c.fastq.gz
d.fastq.gz
If I execute:
sh test.sh --INFILE b.fastq.gz
My desired output would be:
b
Something I tried and failed was,
prefix="sed 's/.fastq//' ${INFILE}"
awk sed command-line filenames
add a comment |
I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.
For example,
I have multiple files:
a.fastq.gz
b.fastq.gz
c.fastq.gz
d.fastq.gz
If I execute:
sh test.sh --INFILE b.fastq.gz
My desired output would be:
b
Something I tried and failed was,
prefix="sed 's/.fastq//' ${INFILE}"
awk sed command-line filenames
add a comment |
I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.
For example,
I have multiple files:
a.fastq.gz
b.fastq.gz
c.fastq.gz
d.fastq.gz
If I execute:
sh test.sh --INFILE b.fastq.gz
My desired output would be:
b
Something I tried and failed was,
prefix="sed 's/.fastq//' ${INFILE}"
awk sed command-line filenames
I want to awk/sed only prefix of name of files, whenever I put a filename as a parameter to my command line.
For example,
I have multiple files:
a.fastq.gz
b.fastq.gz
c.fastq.gz
d.fastq.gz
If I execute:
sh test.sh --INFILE b.fastq.gz
My desired output would be:
b
Something I tried and failed was,
prefix="sed 's/.fastq//' ${INFILE}"
awk sed command-line filenames
awk sed command-line filenames
edited Jan 31 at 18:41


Jesse_b
14.4k33574
14.4k33574
asked Jan 31 at 18:18
JasonJason
255
255
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Using shell parameter expansion (assuming you are assigning your filename to INFILE
):
INFILE=b.fastq.gz
prefix=${INFILE%%.*}
Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):
prefix=${INFILE%.fastq.gz}
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So yourtest.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)
– Jesse_b
Jan 31 at 18:56
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
add a comment |
Using the standard basename
utility to remove the known suffix:
$ basename b.fastq.gz .fastq.gz
b
With a variable:
$ pathname="/some/path/name.fastq.gz"
$ basename "$pathname" .fastq.gz
name
Assigning to a variable:
$ prefix=$( basename "$pathname" .fastq.gz )
$ printf 'Prefix is "%s"n' "$prefix"
Prefix is "name"
In a loop (over all the .fastq.gz
files in the current directory):
for filename in ./*.fastq.gz; do
prefix=$( basename "$filename" .fastq.gz )
# Do things using "$prefix" here
done
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?
– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
add a comment |
Let me fix what you tried in steps, so you can see what you were doing:
$ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
sed 's/.fastq//' b.fastq.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
sed: can't read b.fastq.gz: No such file or directory
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
b.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
b
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%2f497978%2fawk-sed-part-of-filename%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Using shell parameter expansion (assuming you are assigning your filename to INFILE
):
INFILE=b.fastq.gz
prefix=${INFILE%%.*}
Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):
prefix=${INFILE%.fastq.gz}
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So yourtest.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)
– Jesse_b
Jan 31 at 18:56
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
add a comment |
Using shell parameter expansion (assuming you are assigning your filename to INFILE
):
INFILE=b.fastq.gz
prefix=${INFILE%%.*}
Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):
prefix=${INFILE%.fastq.gz}
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So yourtest.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)
– Jesse_b
Jan 31 at 18:56
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
add a comment |
Using shell parameter expansion (assuming you are assigning your filename to INFILE
):
INFILE=b.fastq.gz
prefix=${INFILE%%.*}
Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):
prefix=${INFILE%.fastq.gz}
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
Using shell parameter expansion (assuming you are assigning your filename to INFILE
):
INFILE=b.fastq.gz
prefix=${INFILE%%.*}
Or if your suffix is sure to be fixed and you want to be more precise (always recommended when possible):
prefix=${INFILE%.fastq.gz}
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern and matched according to the rules described below (see Pattern Matching). If the pattern matches If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.
edited Jan 31 at 18:35
answered Jan 31 at 18:33


Jesse_bJesse_b
14.4k33574
14.4k33574
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So yourtest.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)
– Jesse_b
Jan 31 at 18:56
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
add a comment |
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So yourtest.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)
– Jesse_b
Jan 31 at 18:56
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
sorry for beginner question, but getting ERROR ~ unexpected token: . @ line 44, column 18. prefix="${INFILE%.fastq.gz}" ^
– Jason
Jan 31 at 18:47
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
@Jason: What shell are you using?
– Jesse_b
Jan 31 at 18:51
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
usually bash, but the one I am currently working on is groovy.
– Jason
Jan 31 at 18:55
So your
test.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)– Jesse_b
Jan 31 at 18:56
So your
test.sh
script has a hashbang that points to groovy shell? (Sorry not familiar with that one)– Jesse_b
Jan 31 at 18:56
2
2
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
@Jason If you're not working in a standard Unix shell environment, then you'd better let us know about what you're doing. We were assuming you were either using the command line or writing a shell script.
– Kusalananda♦
Jan 31 at 18:57
add a comment |
Using the standard basename
utility to remove the known suffix:
$ basename b.fastq.gz .fastq.gz
b
With a variable:
$ pathname="/some/path/name.fastq.gz"
$ basename "$pathname" .fastq.gz
name
Assigning to a variable:
$ prefix=$( basename "$pathname" .fastq.gz )
$ printf 'Prefix is "%s"n' "$prefix"
Prefix is "name"
In a loop (over all the .fastq.gz
files in the current directory):
for filename in ./*.fastq.gz; do
prefix=$( basename "$filename" .fastq.gz )
# Do things using "$prefix" here
done
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?
– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
add a comment |
Using the standard basename
utility to remove the known suffix:
$ basename b.fastq.gz .fastq.gz
b
With a variable:
$ pathname="/some/path/name.fastq.gz"
$ basename "$pathname" .fastq.gz
name
Assigning to a variable:
$ prefix=$( basename "$pathname" .fastq.gz )
$ printf 'Prefix is "%s"n' "$prefix"
Prefix is "name"
In a loop (over all the .fastq.gz
files in the current directory):
for filename in ./*.fastq.gz; do
prefix=$( basename "$filename" .fastq.gz )
# Do things using "$prefix" here
done
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?
– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
add a comment |
Using the standard basename
utility to remove the known suffix:
$ basename b.fastq.gz .fastq.gz
b
With a variable:
$ pathname="/some/path/name.fastq.gz"
$ basename "$pathname" .fastq.gz
name
Assigning to a variable:
$ prefix=$( basename "$pathname" .fastq.gz )
$ printf 'Prefix is "%s"n' "$prefix"
Prefix is "name"
In a loop (over all the .fastq.gz
files in the current directory):
for filename in ./*.fastq.gz; do
prefix=$( basename "$filename" .fastq.gz )
# Do things using "$prefix" here
done
Using the standard basename
utility to remove the known suffix:
$ basename b.fastq.gz .fastq.gz
b
With a variable:
$ pathname="/some/path/name.fastq.gz"
$ basename "$pathname" .fastq.gz
name
Assigning to a variable:
$ prefix=$( basename "$pathname" .fastq.gz )
$ printf 'Prefix is "%s"n' "$prefix"
Prefix is "name"
In a loop (over all the .fastq.gz
files in the current directory):
for filename in ./*.fastq.gz; do
prefix=$( basename "$filename" .fastq.gz )
# Do things using "$prefix" here
done
edited Jan 31 at 19:05
answered Jan 31 at 18:21


Kusalananda♦Kusalananda
140k17261435
140k17261435
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?
– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
add a comment |
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?
– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
I like this answer. However, this is assuming that you are operating using the BASH shell. While probably a pretty safe assumption, there are a few changes you would need to make if you were working in something like tcsh or straight Bourne shell. If it is Bourne (which it appears is what the poster is using to run their script in the original question), you'll probably want to use backticks "`command`" instead of the "$( command )" construct.
– ParanoidGeek
Jan 31 at 18:58
2
2
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current
/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?– Kusalananda♦
Jan 31 at 19:01
@ParanoidGeek I will not make changes to support non-POSIX shells. This would work with any current
/bin/sh
implementation (which all my answers do unless I specifically mention otherwise). See also Have backticks (i.e. `cmd`) in *sh shells been deprecated?– Kusalananda♦
Jan 31 at 19:01
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
@Kusalananda - I wouldn't ask you do so. As I said, I liked your answer.
– ParanoidGeek
Jan 31 at 19:06
add a comment |
Let me fix what you tried in steps, so you can see what you were doing:
$ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
sed 's/.fastq//' b.fastq.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
sed: can't read b.fastq.gz: No such file or directory
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
b.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
b
add a comment |
Let me fix what you tried in steps, so you can see what you were doing:
$ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
sed 's/.fastq//' b.fastq.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
sed: can't read b.fastq.gz: No such file or directory
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
b.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
b
add a comment |
Let me fix what you tried in steps, so you can see what you were doing:
$ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
sed 's/.fastq//' b.fastq.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
sed: can't read b.fastq.gz: No such file or directory
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
b.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
b
Let me fix what you tried in steps, so you can see what you were doing:
$ INFILE=b.fastq.gz; prefix="sed 's/.fastq//' ${INFILE}"; echo "$prefix"
sed 's/.fastq//' b.fastq.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' ${INFILE})"; echo "$prefix"
sed: can't read b.fastq.gz: No such file or directory
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq//' <<< ${INFILE})"; echo "$prefix"
b.gz
$ INFILE=b.fastq.gz; prefix="$(sed 's/.fastq.*//' <<< ${INFILE})"; echo "$prefix"
b
answered Jan 31 at 23:36
JoLJoL
1,154412
1,154412
add a comment |
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%2f497978%2fawk-sed-part-of-filename%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