What does sed command do? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I have this command:



sed 's/|.*/ /g' filename 


I would like to know what this command does to the datafile, and if there is another command like awk that can replace that command and perform the same function?










share|improve this question















closed as unclear what you're asking by maulinglawns, countermode, GAD3R, Romeo Ninov, RalfFriedl Sep 25 at 17:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
    – Mr Shunz
    Sep 25 at 12:31















up vote
-1
down vote

favorite












I have this command:



sed 's/|.*/ /g' filename 


I would like to know what this command does to the datafile, and if there is another command like awk that can replace that command and perform the same function?










share|improve this question















closed as unclear what you're asking by maulinglawns, countermode, GAD3R, Romeo Ninov, RalfFriedl Sep 25 at 17:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
    – Mr Shunz
    Sep 25 at 12:31













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have this command:



sed 's/|.*/ /g' filename 


I would like to know what this command does to the datafile, and if there is another command like awk that can replace that command and perform the same function?










share|improve this question















I have this command:



sed 's/|.*/ /g' filename 


I would like to know what this command does to the datafile, and if there is another command like awk that can replace that command and perform the same function?







sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 25 at 12:46









Goro

6,42552863




6,42552863










asked Sep 25 at 12:25









juju

372




372




closed as unclear what you're asking by maulinglawns, countermode, GAD3R, Romeo Ninov, RalfFriedl Sep 25 at 17:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by maulinglawns, countermode, GAD3R, Romeo Ninov, RalfFriedl Sep 25 at 17:01


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 4




    Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
    – Mr Shunz
    Sep 25 at 12:31













  • 4




    Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
    – Mr Shunz
    Sep 25 at 12:31








4




4




Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
– Mr Shunz
Sep 25 at 12:31





Hello and welcome to this site! Care to explain a little bit more about what you're trying to achieve? The command as is won't do anything to the file, it just prints the contents substituting the first occurence of | and everything after with a space, on each line. To modify a file you should use the flag -i.
– Mr Shunz
Sep 25 at 12:31











1 Answer
1






active

oldest

votes

















up vote
3
down vote













The command sed has many functions. The command you provided in the question is in the form:



sed 's/this/that/g' filename 


This command will read filename and then replace every this in the filename by that. So your command will replace everything after |.* in the filename by an empty spaces.



Let's break down |.*



*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by , a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use * in these contexts.

.
Matches any character, including newline.


For example:
If filename contain:



|.*2
|.*3
|.*9
|.*10
|.*11
|.*12
|.*24
|.*28
|.*2933


Then the output will be "nothing", because the command sed will replace every |. and the following text represented by * by an empty spaces.



On the other side, if the content of the filename is as follwos:



me|.*2
you|.*3
them|.*9
him|.*10
her|.*11
he|.*12
has|.*24
foo|.*28
bar|.*2933


Then the output of the command will be



me
you
them
him
her
he
has
foo
bar





share|improve this answer






















  • This is not correct Goro. The . and * are regular expressions. Not literals.
    – maulinglawns
    Sep 25 at 12:58










  • @maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
    – Goro
    Sep 25 at 13:06


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













The command sed has many functions. The command you provided in the question is in the form:



sed 's/this/that/g' filename 


This command will read filename and then replace every this in the filename by that. So your command will replace everything after |.* in the filename by an empty spaces.



Let's break down |.*



*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by , a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use * in these contexts.

.
Matches any character, including newline.


For example:
If filename contain:



|.*2
|.*3
|.*9
|.*10
|.*11
|.*12
|.*24
|.*28
|.*2933


Then the output will be "nothing", because the command sed will replace every |. and the following text represented by * by an empty spaces.



On the other side, if the content of the filename is as follwos:



me|.*2
you|.*3
them|.*9
him|.*10
her|.*11
he|.*12
has|.*24
foo|.*28
bar|.*2933


Then the output of the command will be



me
you
them
him
her
he
has
foo
bar





share|improve this answer






















  • This is not correct Goro. The . and * are regular expressions. Not literals.
    – maulinglawns
    Sep 25 at 12:58










  • @maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
    – Goro
    Sep 25 at 13:06















up vote
3
down vote













The command sed has many functions. The command you provided in the question is in the form:



sed 's/this/that/g' filename 


This command will read filename and then replace every this in the filename by that. So your command will replace everything after |.* in the filename by an empty spaces.



Let's break down |.*



*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by , a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use * in these contexts.

.
Matches any character, including newline.


For example:
If filename contain:



|.*2
|.*3
|.*9
|.*10
|.*11
|.*12
|.*24
|.*28
|.*2933


Then the output will be "nothing", because the command sed will replace every |. and the following text represented by * by an empty spaces.



On the other side, if the content of the filename is as follwos:



me|.*2
you|.*3
them|.*9
him|.*10
her|.*11
he|.*12
has|.*24
foo|.*28
bar|.*2933


Then the output of the command will be



me
you
them
him
her
he
has
foo
bar





share|improve this answer






















  • This is not correct Goro. The . and * are regular expressions. Not literals.
    – maulinglawns
    Sep 25 at 12:58










  • @maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
    – Goro
    Sep 25 at 13:06













up vote
3
down vote










up vote
3
down vote









The command sed has many functions. The command you provided in the question is in the form:



sed 's/this/that/g' filename 


This command will read filename and then replace every this in the filename by that. So your command will replace everything after |.* in the filename by an empty spaces.



Let's break down |.*



*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by , a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use * in these contexts.

.
Matches any character, including newline.


For example:
If filename contain:



|.*2
|.*3
|.*9
|.*10
|.*11
|.*12
|.*24
|.*28
|.*2933


Then the output will be "nothing", because the command sed will replace every |. and the following text represented by * by an empty spaces.



On the other side, if the content of the filename is as follwos:



me|.*2
you|.*3
them|.*9
him|.*10
her|.*11
he|.*12
has|.*24
foo|.*28
bar|.*2933


Then the output of the command will be



me
you
them
him
her
he
has
foo
bar





share|improve this answer














The command sed has many functions. The command you provided in the question is in the form:



sed 's/this/that/g' filename 


This command will read filename and then replace every this in the filename by that. So your command will replace everything after |.* in the filename by an empty spaces.



Let's break down |.*



*
Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by , a ., a grouped regexp (see below), or a bracket expression. As a GNU extension, a postfixed regular expression can also be followed by *; for example, a** is equivalent to a*. POSIX 1003.1-2001 says that * stands for itself when it appears at the start of a regular expression or subexpression, but many nonGNU implementations do not support this and portable scripts should instead use * in these contexts.

.
Matches any character, including newline.


For example:
If filename contain:



|.*2
|.*3
|.*9
|.*10
|.*11
|.*12
|.*24
|.*28
|.*2933


Then the output will be "nothing", because the command sed will replace every |. and the following text represented by * by an empty spaces.



On the other side, if the content of the filename is as follwos:



me|.*2
you|.*3
them|.*9
him|.*10
her|.*11
he|.*12
has|.*24
foo|.*28
bar|.*2933


Then the output of the command will be



me
you
them
him
her
he
has
foo
bar






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 25 at 13:05

























answered Sep 25 at 12:55









Goro

6,42552863




6,42552863











  • This is not correct Goro. The . and * are regular expressions. Not literals.
    – maulinglawns
    Sep 25 at 12:58










  • @maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
    – Goro
    Sep 25 at 13:06

















  • This is not correct Goro. The . and * are regular expressions. Not literals.
    – maulinglawns
    Sep 25 at 12:58










  • @maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
    – Goro
    Sep 25 at 13:06
















This is not correct Goro. The . and * are regular expressions. Not literals.
– maulinglawns
Sep 25 at 12:58




This is not correct Goro. The . and * are regular expressions. Not literals.
– maulinglawns
Sep 25 at 12:58












@maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
– Goro
Sep 25 at 13:06





@maulinglawns. Thanks. I found his question is simple BUT legal. Why not answering it? Why downvotes? Would you please either edit my answer and make it clearer or post an answer. Thanks ;-)
– Goro
Sep 25 at 13:06



Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay