sed

Sed: Change case of substitution group

How can I change the case of a matching group from lower to uppercase with sed Unix command? Thanks Martin ...

Unable to understand a line in SED

I run the following code sed 's/\([^ ]+\) your \([^ ]+\)/ \2\1er/' < fail The file fail is fail your test The above command gives me fail your test although it should give "testfailer". The second and first globs \2\1 should be at the start of the word "er". This suggests me that the problem may be in the regexes in the searc...

Unable to source a SED script

I run unsuccessfully cat Research/Skim.app/Contents/Frameworks/SkimNotes.framework/Versions/A/Resources/info.plist | sed -f Users/Masi/bin/HideTopBar and I get sed: Users/Masi/bin/HideTopBar: No such file or directory [439] I get the same error message also for the following command sed -f Users/Masi/bin/HideTopBar Research/Skim....

How do you strip quotes out of an ECHO'ed string in a Windows batch file?

I have a Windows batch file I'm creating, but I have to ECHO a large complex string, so I'm having to put double quotes on either end. The problem is that the quotes are also being ECHOed to the file I'm writing it to. How to you ECHO a string like that and strip the quotes off? UPDATE: I've spent the last two days working on this an...

Turn a single sed command into a reusable Textmate command

I have 7 lines of text: a b c d e f g Now I want to add characters to the end of each line, to end up with: a, b, c, d, e, f, g, I found that I can use the "sed" command and run my selection through sed using "Filter through command" in Textmate sed 's/$/,/' Now, one question remains: how do I turn this into a Textmate command t...

How can I collate and summarize records from a file with Perl?

Hello all, I have a text file in the following format: 211B1 CUSTOMER|UPDATE| 211B2 CUSTOMER|UPDATE| 211B3 CUSTOMER|UPDATE| 211B4 CUSTOMER|UPDATE| 211B5 CUSTOMER|UPDATE| 567FR CUSTOMER|DELETE| 647GI CUSTOMER|DELETE| I want a script that processes the text file and reports the following: "UPDATE" for column CUSTOMER found...

How do I remove colons from a list of MAC addresses?

I'm having a hard time trying to remove the colons in a list of MAC addresses. My file: 00:21:5A:28:62:BF 00:24:81:0A:04:44 Expected Output: 00215A2862BF 0024810A0444 Any ideas on how could I do this? Thanks a lot in advance. ...

sed optimization question (large file modification based on smaller dataset)

Hi all, I do have to deal with very large plain text files (over 10 gigabytes, yeah I know it depends what we should call large), with very long lines. My most recent task involves some line editing based on data from another file. The data file (which should be modified) contains 1500000 lines, each of them are e.g. 800 chars long. ...

Getting sed to Replace Text With Argument

Alright, I know this is a simple question, but I can't seem to get this sed command to work. I'm trying to get a text file and replace one bit of it from placeholder text to a study code. The study code that it is going to replace it with is passed into the script using arguments when the script is first ran. The problem is, when I tr...

How do I delete a matching line, the line above and the one below it, using sed?

I have the following sequence occurring multiple times in a file: yyyy xxxx zzzz I have a regex that matches xxxx. Whenever there is a match, I want to delete that line, the line before (e.g. yyyy) and the line after it (e.g. zzzz). How can I use sed to do this? ...

sed: using variables across multiple lines

I am attempting to "grep" out bind for a specific user from an LDAP log file. The lines I need will be spread across multiple lines in the log. Here is example input: [2009/04/28 17:04:42.414] DoBind on connection 0x7c8affc0 [2009/04/28 17:04:42.414] Bind name:cn=admin,ou=appids,o=admineq, version:3, authentication:simple [2009/04/28 17...

Enumerate substitutions with sed or awk

Given the plain text file with lines bli foo bla abc dfg bli foo bla hik lmn what sed or awk magic transforms it to bli foo_01 bla abc dfg bli foo_02 bla hik lmn so that every occurence of 'foo' is replaced by 'foo_[occurence number]'. ...

Why does this sed command do nothing inside a bash script but work outside?

# join pairs of lines side-by-side (like "paste") sed '$!N;s/\n/ /' The above script comes from the great list of sed one-liners found on sourceforge. I wish to use it in an a bash script but it has no effect if used inside the script. If I pipe the output of the script through it, it joins join pairs of lines side-by-side as descri...

Block replacement in sed

I am trying to replace a block in a file using sed, but with no success. E.g. I want to replace this: for(int i = 0; i < MAX_LOOPS; ++i) { printf("Hello World!"); } With this: int i = 0; while(i < MAX_LOOPS) { printf("Hello World!"); ++i; } ...

How to extract a substring matching a pattern from a Unix shell variable

I'm relatively new to Unix shell scripting. Here's my problem. I've used this script... isql -S$server -D$database -U$userID -P$password << EOF > $test exec MY_STORED_PROC go EOF echo $test To generate this result... Msg 257, Level 16, State 1: Server 'MY_SERVER', Procedure 'MY_STORED_PROC': Implicit conversion from datatype 'VARCHA...

Unable to replace the word in a given folder's contents by Sed/Python/Perl

I have a project where I have folders, subfolders, and files. I need to replace the word Masi by the word Bond in each files. I run the following Sed script called replace unsuccessfully s/Masi/Bond/ in Zsh by sed -f PATH/replace PATH2/project/** It gives me all files, also the ones which do not have Masi, as an output. Sed is n...

Regular epressions in Linux/HPUX

Is there a difference in regular expressions on Linux and on HPUX? I am using them in sed. I am trying the following which works only on Linux: sed -e "s/^\s*ant\s*$/#ant/g" Makefile Now I see that if I remove the '^' then it works on HP too. As far as I understand, this should be supported by both. ...

sed beginner: changing all occurrences in a folder

I need to do a regex find and replace on all the files in a folder (and its subfolders). What would be the linux shell command to do that? For example, I want to run this over all the files and overwrite the old file with the new, replaced text. sed 's/old text/new text/g' ...

How to find text within [] in Sed?

This is similar to a question that has already been asked. However, I am looking for a Sed specific answer. I have text similar to the following: Some sample text [with some extra text].foo I need to grab just the text inside the brackets. My attempts thus far have been futile. I can parse the line with other tools but I can't seem...

simple SED command

I have a html report that comes out of a program we use. Its extremely plain html and id like to work on fixing it up just a bit. What code would I need to do in sed to replace <html> with <html><link rel="stylesheet" type="text/css" href="LivingInStyle.css"> Thanks, Russ ...