The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print the word ss_psm UNIX for Dummies Questions & Answers 0 03-17-2008 11:22 AM
Using first word and print their contents using awk cdfd123 Shell Programming and Scripting 6 10-10-2007 12:12 AM
print selected lines tonet Shell Programming and Scripting 6 10-08-2007 02:50 AM
print selected rows with awk tonet Shell Programming and Scripting 6 09-27-2007 03:23 AM
Print out just a word from the file Kinki Shell Programming and Scripting 8 02-20-2005 08:40 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Location: Cyberjaya, Malaysia
Posts: 9
Print out a selected word.

Hi can anyone assist me on my problem.
I try to grep 1 word in 1 line data. Example like below.

* Data below located in a.txt, i just wanna grep just processing-time = "12"

total-octets = "20080718214210Z" total-pages = "" octets-completed = "20080721064351Z" pages-completed = "2" processing-time = "12"


I searched the threat and found 1 solution like below, unfortunately it is just work if the word located in different row not in 1 line row.

sed -ne '/^[ ]*processing-time/s#^\([^=][^=]*\)=\([^/][^/]*\).*#\12#p'

Please assits thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 07-23-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,022
Code:
sed 's/.*\(processing-time = \"[^"]*\"\).*/\1/g'
Reply With Quote
  #3  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Location: Cyberjaya, Malaysia
Posts: 9
Thanks it is work for me.
1 more, how about if i need to grep 2 words octets-completed = "20080721064351Z" and processing-time = "12" it is located in same 1 file in 1 line data, as below.

Quote:
total-octets = "20080718214210Z" total-pages = "" octets-completed = "20080721064351Z" pages-completed = "2" processing-time = "12"
Reply With Quote
  #4  
Old 07-23-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,059
Code:
sed 's/.*\(octets-completed = \"[^"]*\"\).*\(processing-time = \"[^"]*\"\).*/\1 \2/g'
Reply With Quote
  #5  
Old 07-23-2008
Registered User
 

Join Date: Oct 2007
Posts: 170
Quote:
Originally Posted by anakiar View Post
Thanks it is work for me.
1 more, how about if i need to grep 2 words octets-completed = "20080721064351Z" and processing-time = "12" it is located in same 1 file in 1 line data, as below.
You may get something useful from piping Your search through sed this way:

Code:
echo 'total-octets = "20080718214210Z" total-pages = "" octets-completed = "20080721064351Z" pages-completed = "2" processing-time = "12"'|sed -e 's/ = /=/g;s/ /\n/g'
resulting in
Code:
total-octets="20080718214210Z"
total-pages=""
octets-completed="20080721064351Z"
pages-completed="2"
processing-time="12"
which then can be used in a script or something...

/Lakris
Reply With Quote
  #6  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Location: Cyberjaya, Malaysia
Posts: 9
Thanks Guys, for your help, it is very helpful for me now.
Reply With Quote
  #7  
Old 07-23-2008
Registered User
 

Join Date: Jul 2008
Location: Cyberjaya, Malaysia
Posts: 9
Hi Lakris,

I tried to used your method using the pipe after the echo but it wouldn't work. Sorry if it is my mistake i am new in this shell field. Below is what i did

My Code :
Quote:
$ test=`cat file1.txt`
$ echo $test|sed -e 's/ = /=/g;s/ /\n/g'
Result I get :
Quote:
total-octets="20080718214210Z"ntotal-pages=""noctets-completed="20080721064351Z"npages-completed="2"nprocessing-time="12
If your code are working means i can just sort it more cleanly using row, as the usefull output data.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0