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
Find lines with space between strings Galt Shell Programming and Scripting 5 05-07-2008 11:06 AM
To find multiple strings count in a file salaathi Linux 3 11-28-2007 03:31 AM
Take a folder name and find it in another folder (Complicated) hkhan12 Shell Programming and Scripting 5 09-06-2006 09:25 AM
Using grep to find strings of certain lengths? crabtruck UNIX for Dummies Questions & Answers 4 11-04-2003 03:25 AM
How do I find information about the hardware? Fwurm UNIX for Dummies Questions & Answers 3 10-31-2001 02:23 PM

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

Join Date: Aug 2007
Posts: 40
Find information from complicated strings

Hi experts,

I have the file with these lines:
var1=thu_13:12:32,var2=Microsoft,var3=240ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53
var1=thu_13:13:32,var2=Microsoft,var3=213ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53
var1=thu_13:16:32,var2=Microsoft,var3=654ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1xcv23.53


How can I transform it to:
thu_13:12:32,Microsoft,240ms,Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53
thu_13:13:32,Microsoft,213ms,Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1323.53
thu_13:16:32,Microsoft,654ms,Mozilla/4.0_(sun;_MSIR_3-4;_windows.;_NET_1.1xcv23.53

Fundamentally, I would like to remove "XXXXX=".


Thank you
Reply With Quote
Forum Sponsor
  #2  
Old 02-12-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Code:
sed -e "s/,[^=]*=/,/g;s/^.*=//g" input.txt
Reply With Quote
  #3  
Old 02-12-2008
Registered User
 

Join Date: Aug 2007
Posts: 40
Thank you very much that helps
however,
There are some occasions that the equal sign can be inside a text.
var1=thu_13:12:32,var2=Microsoft,var3=240ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_reg=edit_windows.;_NET_1.1323.53)

so this one should give the result

thu_13:12:32,Microsoft,240ms,Mozilla/4.0_(sun;_MSIR_3-4;_reg=edit_windows.;_NET_1.1323.53)
Reply With Quote
  #4  
Old 02-12-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
assuming your naming convention is var1,var2..var9 then:

Code:
 sed 's/var.=//g' infile
should be sufficient if i've read your question correctly
Reply With Quote
  #5  
Old 02-12-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
Hope this will help u

$ var="thu_13:12:32,var2=Microsoft,var3=240ms,var4=Mozilla/4.0_(sun;_MSIR_3-4;_reg=edit_windows.;_NET_1.1323.53)
"
$ echo $var |awk '{gsub("var.=","");print}'
thu_13:12:32,Microsoft,240ms,Mozilla/4.0_(sun;_MSIR_3-4;_reg=edit_windows.;_NET_1.1323.53)
Reply With Quote
  #6  
Old 02-12-2008
Registered User
 

Join Date: Aug 2007
Posts: 40
It could be anything not just var=.
Thanks guys such a quick response
Reply With Quote
  #7  
Old 02-12-2008
Registered User
 

Join Date: Nov 2007
Posts: 85
Friend you had seen how to replace a pattern using sed and awk, try to find a common pattern for the string to be replaced for Eg:
echo $var |awk '{gsub(",....=",",");print}'
this will replace ,xxxx= with ,
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 06:48 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