Output formatting help needed.
Hi guys ,
I have a file which contains following string.(filename tempdisplay) (location 0.0.0.0:5900) i needed to write a script which will extract the string that comes after 0.0.0.0 i.e the string :5900. I have used following method to extract the string :5900 .Is it a preferred way of doing the job? sed s/"(location 0.0.0.0"/""/ tempdisplay > temp2display #temp2display will now contain :5900) temp=`sed s/")"/""/ temp2display` #temp will now contain :5900 echo $temp output: :5900 Please help me with the syntax of the script. |
so what have you tried...?if you have not started to learn shell scripting yet, see my sig to learn bash.
|
Quote:
but i think sed only takes input from a file. but above mentioned string is a output of a command and i want the output should be formated according to my need. can u help me out with this bro. |
Is there any better way of doing this.
|
man cut
|
Quote:
Code:
$ echo "(location 0.0.0.0:5900)" | awk -F":" '{print $NF}' |
Quote:
|
use gsub() or sub(). i repeat again. please start reading the docs (see my sig)
|
The simplest command that i have used is :grep -o ':[0-9]*' tempdisplay
|
All times are GMT -5. The time now is 06:30 PM. |