LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Output formatting help needed. (https://www.linuxquestions.org/questions/linux-newbie-8/output-formatting-help-needed-766363/)

pinga123 11-02-2009 09:44 PM

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.

ghostdog74 11-02-2009 09:49 PM

so what have you tried...?if you have not started to learn shell scripting yet, see my sig to learn bash.

pinga123 11-02-2009 11:33 PM

Quote:

Originally Posted by ghostdog74 (Post 3742080)
so what have you tried...?if you have not started to learn shell scripting yet, see my sig to learn bash.

I m doing it using a sed program
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.

pinga123 11-03-2009 12:57 AM

Is there any better way of doing this.

chrism01 11-03-2009 01:01 AM

man cut

ghostdog74 11-03-2009 01:04 AM

Quote:

Originally Posted by pinga123 (Post 3742212)
Is there any better way of doing this.

of course, one way
Code:

$ echo "(location 0.0.0.0:5900)" | awk -F":" '{print $NF}'
5900)

look at my sig for learning awk.

pinga123 11-03-2009 02:50 AM

Quote:

Originally Posted by ghostdog74 (Post 3742220)
of course, one way
Code:

$ echo "(location 0.0.0.0:5900)" | awk -F":" '{print $NF}'
5900)

look at my sig for learning awk.

How can i remove ) from 5900) in just one line.

ghostdog74 11-03-2009 03:00 AM

use gsub() or sub(). i repeat again. please start reading the docs (see my sig)

pinga123 11-03-2009 06:34 AM

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.