sed

sed + regular expression: how to get everything before a given character

Hi, I have a property files that contains things like: myhome=/home/username lib=/home/libs and I want to, for instance, get the home path (i.e. /home/username): If I use cat + grep like cat property | grep myhome then I get: myhome=/home/username so I could use sed to remove the 'home=', i.e. remove everything before (and inclu...

grep and sed - replace all instances of a string

I have a bash script I'm writing that greps for a filepath. I want to be able to use the output of the grep to replace each instance of the old filepath with the new filepath. Example: grep -R "/~test/dev/portal" . I want to be able to pipe this output into sed to replace each instance of "/~test/dev/portal/" with "/apps/portal/" (k...

Remove previous lines then join when SED finds expression

Hi all, I'm trying to join sentences in a document, but some of the sentences have been split apart with an empty line in between. For example: The dog chased after a ball that was thrown by its owner. The ball travelled quite far. to: The dog chased after a ball that was thrown by its owner. The ball travelle...

Linux command to remove leading zeros from a file name

I have a directory with a bunch of files with names like: 001234.jpg 001235.jpg 004729342.jpg I want to remove the leading zeros from all file names, so I'd be left with: 1234.jpg 1235.jpg 4729342.jpg I've been trying different configurations of sed, but I can't find the proper syntax. Is there an easy way to list all files in the...

Escaping sed strings correctly

I have a regex and replacement pattern that have both been tested in Notepad++ on my input data and work correctly. When I put them into a sed expression, however, nothing gets matched. Here is the sed command: # SEARCH = ([a-zA-Z0-9.]+) [0-9] (.*) # REPLACE = \2 (\1) sed -e 's/\([a-zA-Z0-9.]+\) [0-9] \(.*\)/\2 \(\1\)/g' Here is...

Google API to find the search count

When I google for something, I get the count. Results 1 - 10 of about 800 Is there any API or something like that to capture the number "800"? I have a database of a few thousand words and I want the google count against it. ...

help required for seperating sublists with colon

Hi, I am new to linux and am trying to parse a bunch of files that looks as follows - Some text start list some other text start sublist1 continue sublist1 more elements more elements2 a sublist2 a sub-sublist1 Where all the spaces before the list are tabs. I need a way to parse the text so that a colon is added for sublist...

sed with & in variable

hi, I would like to search and replace with sed and replace with something in a variable wich is containing some specials symbols like &. For example I done something like that: sed "s|http://.*|http://$URL|" where URL=1.1.1.1/login.php?user=admin&pass=password. I thinks it became a problem because I use ? and & in my variable. How...

PCRE regex to sed regex

First of all sorry for my bad english. I'm a german guy. The code given below is working fine in PHP: $string = preg_replace('/href="(.*?)(\.|\,)"/i','href="$1"',$string); Now T need the same for sed. I thought it should be: sed 's/href="(.*?)(\.|\,)"/href="{$\1}"/g' test.htm But that gives me this error: sed: -e expression #1...

select part of filename using regex

I got a file that looks like dcdd62defb908e37ad037820f7 /sp/dir/su1/89/asga.gz 7d59319afca23b02f572a4034b /sp/dir/su2/89/sfdh.gz ee1d443b8a0cc27749f4b31e56 /sp/dir/su3/89/24.gz 33c02e311fd0a894f7f0f8aae4 /sp/dir/su4/89/dfad.gz 43f6cdce067f6794ec378c4e2a /sp/dir/su5/89/adf.gz 2f6c584116c567b0f26dfc8703 /sp/dir/su6/895/895.gz a864b7...

Compare file with variable list AWK

I'm stumbling over myself trying to get a seemingly simple thing accomplished. I have one file, and one newline delimited string list. File: Dat1 Loc1 Dat2 Loc1 Dat3 Loc1 Dat4 Loc2 Dat5 Loc2 My list is something like this: Dat1 Dat2 Dat3 Dat4 What I am trying to do is compare the ...

Linux Text File Manipulation

Hi, I have a file of the format: <a href="http://www.wowhead.com/?search=Superior Mana Oil"> <a href="http://www.wowhead.com/?search=Tabard of Brute Force"> <a href="http://www.wowhead.com/?search=Tabard of the Wyrmrest Accord"> <a href="http://www.wowhead.com/?search=Tattered Hexcloth Sack"> I need to select the text after the = but ...

Linux Text File Manipulation with sed/awk

Hi, I have a list in the following format 77 Infinite Dust 4 Illusion Dust 12 Dream Shard 29 Star's Sorrow I need to change this to: 77 <a href="http://www.wowhead.com/?search=Infinite Dust">Infinite Dust</a> 4 <a href="http://www.wowhead.com/?search=Illusion Dust">Illusion Dust</a> 12 <a href="http://www.wowhead.com/?search=Dream...

Combine Text Lines That Match Criteria, Linux/sed/awk?

Hi I have a file like the following: 1, cake:01351 12, bun:1063 scone:13581 biscuit:1931 14, jelly:1385 I need to convert it so that when a number is read at the start of a line it is combined with the line beneath it, but if there is no number at the start the line is left as is. This would be the output that I need: 1,cake:01351 12...

replace a particular value in a string of key - values

I have a large string which is a collection of key (space)+ value, i.e key followed by one or more space and then value. Now i need to change the value of a particular key using sed, awk, grep etc. in unix environment. eg. of string: -Key1 Value1 -Key2 Value2 -Key3 Value3 I need a new string that is same as above only Va...

unix shell script to remove blank lines following opening brackets

Hi all, I need a (sed, awk) shell script or, even better, a vim command to remove any blank lines following a line with a single opening curly bracket: void func() { foo(); } void bar() { helloWorld(); } should become: void func() { foo(); } void bar() { helloWorld(); } Any thoughts? ...

Delete specific line number(s) from a text file using sed?

I want to delete one or more specific line numbers from a file. How would I do this using sed? ...

Bash output as Applescript list problems.

This is just driving me nuts. I am trying to read a file in bash, remove duplicates, sort, and then display a "list choice" window via applescript. My $DATALOG file is formatted like this: field1 field2 field1 field3 field1 field4 etc... Applescript=awk '{print $2}' $DATALOG | awk ' !x[$0]++' | sort -u | tr "_" " "| sed 's/^/\"/'...

Basic Regexp Question: How to modify only the lines starting with a STRING with sed

I have to replace all ocurrences of: 5.6xx and 5.5xx (where x is a 0-9 digit) on a textfile with 5.500, but only when the line that contains the match starts with a string (e.g. STARTSTRING). That means STARTSTRING 5.610 4.500 3.550 5.530 OTHERSTRING 5.600 5.500 5.500 5.600 should become STARTSTRING 5.500 4.500 3.550 5.500 OTHERSTRIN...

Remove all lines between two strings

In a sh shell script. Given data in a text file: string1 string2 gibberish gibberish string3 gibberish string4 How could you use awk or sed to remove all lines between string2(inclusive) and string3(not including string 3)? to end up with: string1 string3 string4 ...