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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-12-2008
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
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
  #2 (permalink)  
Old 02-12-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798

Code:
sed -e "s/,[^=]*=/,/g;s/^.*=//g" input.txt

  #3 (permalink)  
Old 02-12-2008
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
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)
  #4 (permalink)  
Old 02-12-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
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
  #5 (permalink)  
Old 02-12-2008
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
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)
  #6 (permalink)  
Old 02-12-2008
lalelle lalelle is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 43
It could be anything not just var=.
Thanks guys such a quick response
  #7 (permalink)  
Old 02-12-2008
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
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 ,
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0