LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   get a substring with a bash command (https://www.linuxquestions.org/questions/linux-general-1/get-a-substring-with-a-bash-command-522709/)

xeon123 01-25-2007 10:13 AM

get a substring with a bash command
 
Hi,

i've a file that has the following content:

<param>1</param>
<param>2</param>
<param>3</param>
...
<param>n</param>

I want to use a bash command that put to the output only the values:
1
2
3
...
n

How is this possible?

Thanks,
Pedro

Matir 01-25-2007 10:56 AM

Code:

sed 's/^<param>\(.*\)<\/param>$/\1/'

xeon123 01-25-2007 11:36 AM

Thanks, for the answer.
And, which bash command should i use to remove the spaces from the beginning of each line?

Thanks,
Pedro

ygloo 01-25-2007 03:22 PM

sed 's/^ *//g' file
to see output

sed -i.bak 's/^ *//g' file
to edit file in place and make backup

xeon123 01-26-2007 03:50 AM

Thanks for the aswner


All times are GMT -5. The time now is 07:11 PM.