Skip to main content
Corrected Mistake
Source Link

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

This is how it is suppsed to work

Input: "-Wall"
Output: "-Wall"

Input: "-O3%## -Wall"
Output: "example""-O3"

Input: "%#$#$"
Output: ""

Can anyone show how would it look like using sed?

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

This is how it is suppsed to work

Input: "-Wall"
Output: "-Wall"

Input: "-O3%## -Wall"
Output: "example"

Input: "%#$#$"
Output: ""

Can anyone show how would it look like using sed?

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

This is how it is suppsed to work

Input: "-Wall"
Output: "-Wall"

Input: "-O3%## -Wall"
Output: "-O3"

Input: "%#$#$"
Output: ""

Can anyone show how would it look like using sed?

I show how is it supposed to work
Source Link

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

This is how it is suppsed to work

Input: "-Wall"
Output: "-Wall"

Input: "-O3%## -Wall"
Output: "example"

Input: "%#$#$"
Output: ""

Can anyone show how would it look like using sed?

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

Can anyone show how would it look like using sed?

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

This is how it is suppsed to work

Input: "-Wall"
Output: "-Wall"

Input: "-O3%## -Wall"
Output: "example"

Input: "%#$#$"
Output: ""

Can anyone show how would it look like using sed?

Source Link

Using sed instead of grep to output only matching part of line

I am writing simple bash script (actually learning how to do it ) and i want this function to use just echo and sed and return exactly the same output. I found solutions with sed, they worked in console but did not work inside of script. (script is called with sudo, maybe it's important)

This is my function:

function strip { echo "$1" | grep -oP '[a-zA-Z0-9\+\-\=\ ]+' | head -n 1; } 

Can anyone show how would it look like using sed?