sed

[sed] Printing text between regexps

I tried the '/pat1/,/pat2/p', but I want to print only the text between the patterns, not the whole line. How do I do that? ...

how to use sed to delete some string

In my case text: 21 130.104.72.201 3124 HTTP [C]±ÈÀûʱ ·¨Óï³ãëÌìÖ÷½Ì´óѧ 03-05 14:34 0.238 22 129.108.202.10 3128 HTTP [C]ÃÀ¹ú µÂ¿ËÈø˹´óѧ 03-05 14:08 1.983 23 130.88.203.27 3128 HTTP [C]Ó¢¹ú Âü³¹Ë¹ÌØ´óѧ 03-05 14:08 0.996 24 129.74.152.66 3124 HTTP [C]·¨¹ú ʥĸÂêÀûÑÇ´óѧ 03-05 14:08 0.922 command: sed 's/HTTP.*://' ip_all02.txt ...

sed + cut words before the first “END” word in line

Hi all How to cut words before the first “END” word in line, and not include the first character before the “END” word ( in our examples the character is “-“) Only with sed command For example: echo AAA-BBB-CCC-END | sed ... AAA-BBB-CCC echo 1-END-3-4 | sed ... 1 echo 1-2-END-3-4 | sed ... 1-2 echo PARAM1-PA...

editing multiple HTML files using SED or something similar

At my work I have about 1000 html files (probabaly more) to edit which represent footnotes in a large technical document. I have been asked to go through the html files one by one and manually edit the HTML, to get it all on the straight and narrow. I know that this could probabaly be done in a matter of seconds with SED as the change...

What is newline character -- '\n'

Hi, This is a very basic concept, but something I have never been able to articulate that well. and I would like to try to spell it and see where I go wrong. If I have to, how would I define a "newline character". say if I create a new file in unix(or windows), then does the file store the "end of line" information by inserting a speci...

How to replace many intermediate blank lines with only 1 blank line each..

Hi all, I am learning to use sed and have a hypothetical requirement: bash$ cat states California Massachusetts Arizona Wisconsin I would like the output: (Basically I want only one blank line in between) California Massachusetts Arizona Wisconsin Please suggest ways to do it with sed. Should it use concept of multiline pa...

How to replace 3rd word in a line using sed..

Hi all, This is my 3rd post in the process of learning sed. I have a hypothetical requirement. I want to be able to replace 3rd word in each line by 'was', where words are delimited by space(s). bash$ cat words hi this is me here hi this is me again hi this is me yet again hi this is me Desired output: hi this was me h...

Appending to line with sed, adding separator if necessary

Hi I have a properties file, which, when unmodified has the following line: worker.list= I would like to use sed to append to that line a value so that after sed has run, the line in the file reads: worker.list=test But, when I run the script a second time, I want sed to pick up that a value has already been added, and thus adds a...

sed beginner question: capturing groups in sed

I have many lines of the form ko04062 ko:CXCR3 ko04062 ko:CX3CR1 ko04062 ko:CCL3 ko04062 ko:CCL5 ko04080 ko:GZMA and would dearly like to get rid of the ko: bit of the right-hand column. I'm trying to use sed, as follows: echo "ko05414 ko:ITGA4" | sed 's/\(^ko\d{5}\)\tko:\(.*$\)/\1\2/' which simply outputs the original string I ech...

How to Sort Output from several Log Files by date

Hi, I have got output from several different log files: logfile3 2010/07/21 15:28:52 INFO xxx 2010/07/21 15:31:25 INFO xxx 2010/07/21 15:31:25 DEBUG xxx logfile1 2010/07/21 19:28:52 INFO xxx 2010/07/21 19:31:25 INFO xxx 2010/07/21 19:31:25 DEBUG xxx logfile2 2010/07/21 13:28:52 INFO xxx 2010/07/21 13:31:25 INFO xxx 2010/07/21 13:31:2...

replace a string in shell script

i am using the below code for replacing a string inside a shell script. echo $LINE|sed -e 's/12345678/"$replace"/g' but its getting replaced with $replace instead of the value of that variable. could anybody tell what went wrong. ...

sed + awk + verify line in file

hi I have the following example file /etc/sysconfig/network/script.sh = -exe $Builder run_installation 123 44 556 4 = run_installation arg1 arg2 arg3 948 EXE=somthing EXE somthing I have three questions (I write bash script) how to verify by sed or awk if the string "-exe" exist after "=" character how to verify by...

sed + how to get the second word (string) after "=" separator by sed

hi how to get the second word (string) after "=" separator by sed (need to ignore spaces) for example echo " bla bla word word1 = strin1 string2 " | sed ..... I should get string2 another example echo " bla bla word word1 =swhsw 123 " | sed ..... I should get 123 please advice lidia ...

sed/awk + line manipulation

hi all I have two different questions(on both questions need to ignore spaces) How to print all lines until "=" separator for example echo " bla bla girl man dog = black white color bla 123 4" | sed/awk ..... Will print: bla bla girl man dog the second question How to print all lines from "=" until end of line echo ...

(unix shell scripting) Trim last 3 characters of a line WITHOUT using sed, or perl, etc.

Hi, I've got a shell script outputting data like this: 1234567890 * 1234567891 * I need to remove JUST the last three characters " *". I know I can do it via (whatever) | sed 's/\(.*\).../\1/' But I DON'T want to use sed for speed purposes. It will always be the same last 3 characters. Qny quick way of cleaning up the output? ...

sed command line

Hi I need to run 'sed' command on file1.txt and have it extract all names that are in between StringA and StringB... ex: "Nickname":"bad_name", extract bad_name and then save all results too Output.txt. is this even possible or should I be looking at another command? ...

GNU sed - find or replacing spaces or new lines. Why is this not working? v3.02 vs v4.2

C:\crp\cnp>sed -V GNU sed version 3.02 Copyright (C) 1998 Free Software Foundation, Inc....... C:\crp\cnp>type f.f a a a a a a Trying to replace 'a' with spaces. C:\crp\cnp>type f.f | sed -e s/a/\d032/g d032 d032 d032 d032 d032 d032 why isn't it working? I don't mind whether i'm finding or replacing spaces or new lines.. I ...

sed + replace only if match the first word in line

hi all The following sed command replaces the OLD string with the NEW string. My target is to replace the OLD to NEW only if COMMAND word appears as the first word in the line. How to fix my sed syntax in order to replace OLD with NEW only if COMMAND is the first word in line? (Note: COMMAND word location could be after some spaces fro...

sed + match directory PATH from line by sed

hi have in file the example line: (in file) PATH: word1 /var/tmp word2 word3 how to rescue or match only "/var/tmp" PATH from the line by sed remark: /var/tmp its only example , it could be any other path! remark1: /var/tmp could be in the first line or in the end of the line or somewhere in the middle of line for example echo "...

Delete strings from an html file containing a pattern using unix commands

Hi, I have a messy html that looks like this: <div id=":0.page.0" class="page-element" style="width: 1620px;"> <div> <img src="viewer_files/viewer_004.png" class="page-image" style="width: 800px; height: 1131px; display: none;"> <img src="viewer_files/viewer_005.png" class="page-image" style="width: 1600px;"> </div> </div>// this ...