sed

Shell: How to replace something of a text with the saved variable value

I saved a value by shell command: For example: timeoutvalue=`echo "timeout=2.0"` And I have to grep the value of timeout from another text, and replace it with this timeoutvalue. For example, the text is egtest: <host ip="255.255.255.0" name="testhost" description="hostfortest" connection="xmlrpc" timeout=4.0/> I want to grep the v...

Regex: Help with extracting a filed from the text and replace the value of the field

I have to extract a parameter from a configuration file, and replace its values with another given value. The config file is: <host ip="200.200.200.200" name="testhost" description="test server" type="TEST_Duplex " connection="xmlrpc" xmldefaulttimeout="2.0" xmlspecifictimeout ="8.0"/> I have to replace the value of xmldefaulttimeout=...

using awk or sed to compare

Hi, I am having a file that has the following lines say 13:26:35.655029 (TN) sh:sdf:sdf > ra:ram:raml, type Normal (800), length 21: ID 10.1.1.1 > 20.2.2.2: Addr 77: TP 13:26:35.656029 (TN) ra:ram:raml > sh:sdf:sdf, type Normal (800), length 21: ID 20.2.2.2 >10.1.1.1: Addr 77: TP I need to get sh:sdf:sdf , ra:ram:raml ,10.1.1.1 , ...

how to print a section of file between two regular expressions only if a line within the section contains a certain string within it

Hi I have a file of events that has multiple multi lined events between <event> and </event> tags. I want to print out the entire event From <event> to </event> only if a line within that event contains either the string uniqueId="1279939300.862594_PFM_1_1912320699" or uniqueId="1281686522.353435_PFM_1_988171542". The file has 100000 eve...

sed extract data from dos text file convert to csv

I need to pull RAM information from several cpuz reports and put them into a csv for reporting reasons. below is an example text file (snipped) which contains the text i want to extract. I want to extract all the text following the lines beginning with DIMM but only where the next line begins with tab and SMBus address, and going down t...

Extract HTML tag data with sed

I wish to extract data between known HTML tags. For example: Hello, <i>I<i> am <i>very</i> glad to meet you. Should become: 'I very' So I have found something that works to nearly do this. Unfortunately, it only extracts the last entry. sed -n -e 's/.*<i>\(.*\)<\/i>.*/\1/p' Now I can append any end tag </i> with a newline characte...

sed + match line and add word on the first string in line

I have the following file more file machine1 network netmask broadcast how to add the "_NAME" after the first word in the line that have the "network netmask broadcast" words ? remark sed also need to match only "network netmask broadcast" and then to add _NAME to the first word in the line example: what I need to get af...

Adding an incrementing value attribute to every tag in xml using script

I want to add an attribute to every tag in my xml, which is incrementing using either awk, sed, perl or plain shell cmd For Eg: <tag1 key="123"> <tag2 abc="xf d"/> <tag3 def="d2 32"> </tag3> </tag1> I am expecting the following output <tag1 key="123" order="1"> <tag2 abc="xf d" order="2"/> <tag3 def="d2 32" order="3"> ...

what does this sed expr. match actually? s/^.*EngineLog ERROR://

sed Expression 's/^.*EngineLog ERROR://' ...

Using sed to combine multiple csv files

I have 3 csv files I'd like to combine. Each file has 3 comma delimited columns. File 1 has columns a,b,c File 2 has columns d,e,f File 3 has columns g,h,i I'd like to combine the 3 files into a single file of: a,b,c,e,f,h Can I use sed to do that? I could write a console app or script easily enough but I'm attempting to get some...

sed on sun solaris

hi I am try to do the following on sun solaris sed "/ADDRESS/a \ PROTOCOL" file > NEW_file but I get: sed: command garbled: /ADDRESS/a PROTOCOL why (on linux its work) , is it possible to support syntax that work on linux and on sun lidia ...

sed + without cat command

hi the following syntax target is to add "_name4" on the first string in line that match the "name1 + name2 + name3" and to replace old word with new cat file | sed '/name1 + name2 + name3/s/[^ ]*\>/&_name4/' | sed s'/old/new/g' > new_file my question : is it possible to do the same without using cat command? ...

sed + match the first word in line and the second word that begin with abc

How to match all lines that begins with word ADDRESS and the second string start with abc characters. remark - ( I need to combine the sed syntax in my shell script) for example more file ADDRESS abc1a (match) ADDRESS abc1b (match) ADDRESS acb1a (will not match) ADRESS abc (will not match) ADDRESS abc2a (will match) ADDRE...

vim removing xml tags

I have a one liner in vim which I regularly use for find and replace. I now want to use it to remove tags - something like this but I looks like I need to escape the / I'm not sure what am I missing. :%s~<Validator>*</Validator>~~g ...

Sed / awk script to correct illegal characters from XML (ampersand)

For parsing an invalid XML file, having either unencoded, illegal characters (ampersands in my case): <url>http://example.com?param1=bad&amp;param2=ampersand&lt;/url&gt; and encoded ones <description> The good, the bad &amp; the ugly </description> Please post an example with a sed/awk script that can encode the illegal characters....

sed command to write the name of file to HTML comment

I'm looking for a sed command that, with find, I can take a directory tree of JSP files and write the name of the file in an HTML comment to the top of the file. This will allow me to review a legacy application JSP call tree of in the HTML source. I'm thinking it will be a one liner for a talented sed guru... something like: find ....

Parsing using awk or sed in Unix

Hi, I have multiple files with hundreds of thousands of records in following format: 2010/08/10 10:07:52|TrainZoom|1393|38797|MyCustomerAPI->,mask = ZPTA,TransId = 1281460071578,testing :-> , capture -> : , IMDB = 9113290830, equipmentName = GMT, technologyName = RMS,,,)| There are fields separated by pipes and inside...

How to count number of non empty lines in a file using sed?

hi all how to find how many lines I have in file by sed (need to ignore spaces and empty lines) for example if I have file with 139 lines (line can include only one character) then sed should return 139 lidia ...

Extract every nth letter (number)

I have a file with line: name, space and string of zero and one, and I need to extract every 5nth character of the string of zero and one, make a sum of the results and if the sum is not 0 - save the name into the other file. 1rt2 0001000000100000000000001010000100000000010000001000000100010010000000000000 1gh4 0001000000100000000000001...

How can I say this in sed?

I have text text text [text text] \n text text text [text text] \n I want text text text \n text text text \n What RE can I use? ...