![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
sed -e "s/,[^=]*=/,/g;s/^.*=//g" input.txt |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
assuming your naming convention is var1,var2..var9 then:
Code:
sed 's/var.=//g' infile |
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
It could be anything not just var=.
Thanks guys such a quick response |
|
#7
|
|||
|
|||
|
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 , |
|||
| Google The UNIX and Linux Forums |