Find information from complicated strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find information from complicated strings
# 1  
Old 02-12-2008
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  
Old 02-12-2008
Code:
sed -e "s/,[^=]*=/,/g;s/^.*=//g" input.txt

# 3  
Old 02-12-2008
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  
Old 02-12-2008
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  
Old 02-12-2008
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  
Old 02-12-2008
It could be anything not just var=. Smilie
Thanks guys such a quick response
# 7  
Old 02-12-2008
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 ,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Command to find the harddisk information

I tried to find the harddisk information using the command hdparm -i /dev/sda. But I couldn't get the info. Is there any similar command to find the harddisk serial number. (5 Replies)
Discussion started by: gsiva
5 Replies

2. UNIX for Dummies Questions & Answers

Where to find Kernel development Information

Hi, I would like to do some research on the Linux kernel. Where can I find information about the current kernel development, who is working on the kernel. I looked up the change log on the kernels main page, but that doesn't help either. My goal is to find out where the focus of the current... (3 Replies)
Discussion started by: Learn4Life
3 Replies

3. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

4. Programming

GDB - how to find interesting information?

Hi all, I was wondering how to find interesting information inside the assembly code. As example, I've been trying something at smashthestack wargame. After viewing the assembly code via disassemble main command, I'm not sure what else to do. Hopefully someone can guide me here. This is... (2 Replies)
Discussion started by: type8code0
2 Replies

5. Shell Programming and Scripting

complicated exclude option in find command

Hi all, In a directory, I have many video files. Example : As you can see, some of the video files come with a .aspx file (wich means the video is actually being uploaded and not entirely written on the FS) I try to write a bash script that would find all video files in the ... (1 Reply)
Discussion started by: gniagnia
1 Replies

6. Shell Programming and Scripting

Search complicated strings on file

Can someone help me? I been figuring out how I can search and extract a complicated search string from a file. The whole string is delimited by a period. And the file where I'm searching is composed of differnt string such as that. For example, I have this search string: and I have a file... (3 Replies)
Discussion started by: Orbix
3 Replies

7. Shell Programming and Scripting

find information about logins

Hi, all I want to make a bash script that print all users from a system using last command. I want to print the number of user's login in the format (descending order): 5 user1 address1 4 user2 address2 I am trying the command last | awk '{print $1 " " $3}' | sort | uniq ... (9 Replies)
Discussion started by: peter20
9 Replies

8. Shell Programming and Scripting

Take a folder name and find it in another folder (Complicated)

Hi Script Experts, Here is my scenario: 1. /var/mqm/qmgrs folder will contain 11 folders as follows: 1. /var/mqm/qmgrs/Folder_Name1 ....................../Folder_Name2 ....................../Folder_Name3 ....... ...................../Folder_Name11 2. if Folder_Name1 exists... (5 Replies)
Discussion started by: hkhan12
5 Replies

9. UNIX for Dummies Questions & Answers

How do I find information about the hardware?

Hello I used to Red Hat and the common Linux commands, but now I have to deal with a SCO-Unix (Unix Ware 7). I have to find information about the hardware. What networkcard is installed? What graphiccard is installed? Which SCSI-Adapter and what kind of harddisks? What software is... (3 Replies)
Discussion started by: Fwurm
3 Replies

10. UNIX for Dummies Questions & Answers

Please help me find out system information

I'm just getting started with unix and would like to know 1) how to tell how big the harddrive is 2) how to tell if there are multiple harddrive installed on the machine 3) a relitavely easy way to tell what programs are installed on the machine. I'm using Sun OS 5.6 Thanks (3 Replies)
Discussion started by: ViperD
3 Replies
Login or Register to Ask a Question