sed

sed on OS X - can't seem to use + in regexps

Now according to all the literature echo 1234abcd|sed "s|[0-9]\+|#|g" should return #abcd. And echo abcd|sed "s|[0-9]\+|#|g" should return abcd. But on OS X 10.4.11 the first expression returns 1234abcd. Using * instead of + works for the first example but fails on the second, returning #abcd, because the [0-9] pattern is matched ...

Sed - html replacement

Here is the input I have and the output I want: Input: <hr /> (newline) ( carriage return) (tabs, spaces)<div id="sidebar"> Output: </div> <hr /> (newline) ( carriage return) (tabs, spaces)<div id="sidebar"> This doesn't seem to match it: sed -i 's/<hr \/>[[:space:]]*<div id="sidebar">/<\/div><hr \/><div id="sidebar">/g...

How can I ensure a Bash string is alphanumeric, without an underscore?

I'm adding a feature to an existing script that will allow the user to configure the hostname of a Linux system. The rules I'm enforcing are as follows: Must be between 2 and 63 characters long Must not start or end with a hyphen Can only contain alphanumeric characters, and hyphens; all other characters are not allowed (including an u...

How do I insert a line at a specific row in multiple files on Unix?

I need to insert a line with specific text on the second line (thus moving the other lines down in the file) of hundreds of files in a directory. Any quick Unix tips on how that can be done? ...

need help removing time from a csv file

im trying to process a csv and make it easier for sorting, and i need to remove the time and the dash from it. the file has entries like this: James,07/20/2009-14:40:11 Steve,08/06/2006-02:34:37 John,11/03/2008-12:12:34 and parse it into this: James,07/20/2009 Steve,08/06/2006 John,11/03/2008 im guessing sed is the right tool for t...

Linux command to replace string in LARGE file with another string

I have a huge SQL file that gets executed on the server. The dump is from my machine and in it there are a few settings relating to my machine. So basically, I want every occurance of "c://temp" to be replace by "//home//some//blah" How can this be done from the command line? ...

Sed Out of a Pair of Words

One can use a command such as the following to substitute the word "before" to the word "after" where "before" occurs between the pair of words "begin" and "end": sed '/begin/,/end/ {s/before/after/g}' I am looking for a way to substitute "before" by "after" only if they do not occur inside a pair of "begin" and "end". ...

Apply sed to crontab lines ?

I want to programatically change the hour which certain cron jobs execute. I'm not sure whether I'm going about this the right way, but here's the plan. Jobs which are subject to change will have a comment on the end of the line "#change-enabled". 15 5 7,14,21,28 * * /path/to/executable1 #change-enabled 15 * * * * /path/to/executable2 ...

SED: How can I replace a newline (\n)?

I unsuccesfully tried: sed 's#/\n# #g' file sed 's#^$# #g' file How to fix it? ...

sed: Prepend every line with the hold space.

I'm trying to convert a large number of files from a plain text layout to CSV. The first few lines of one of the files looks like this: SLICE AT X= -0.25 ELEM NO XI-COORD INWARD-NORMAL 1 0 0.000 0.000 0.000 0.000 0.000 0.000 2 0 0.000 0.000 0.000 0.000 0.000 0.000 3 ...

A regex for a class definition in java

The problem is as follows: There is a massive codebase in Java (hundreds of files in tens of packages) where we need the ability to add and remove the keyword strictfp in each class definition. I am planning to use either sed or awk to perform this substitution. However, I would like to avoid the word "class" in comments or elsewhere fr...

grab frequent username from 'last' command in unix - with exceptions

If I run this on OS X: last -10 | awk '{print $1}' I get: chop chop chop chrihopk reboot shutdown chop chop chop chrihopk How do I use sed or awk to obtain the most frequent user 'chop'? ADDITIONAL EDIT TO QUESTION: Our local admin account interferes with the results (username: support) and often we have a new starter on a clie...

How can I translate these sed and perl one-liners to informatica?

Duplicate: http://stackoverflow.com/questions/1259545/let-me-know-alternate-command-in-dos-for-following-sed-and-perl-commands-closed the following commands have unique implementation in unix box. Need to implement in informatica(etl tool). If not any windows solution for the same sed 's/^#//g' < kam_account_calls.txt > kam_account_...

Help with SED syntax : unterminated `s' command

Edit: I'm using CYGWIN/GNU sed version 4.1.5 on windows Vista and I want a case insensitive search I want to use sed to replace inline, the following: c:\DEV\Suite\anything here --- blah 12 334 xxx zzzzz etc\Modules etc Edit: anything here --- blah 12 334 xxx zzzzz etc means anything could appear here. Sorry for omitting that. In...

need same logic in windows as been done by SED below

sed 's/^#//g' < kam_account_calls.txt > kam_account_calls1.txt This command removes # from the start of the line. Please let me know how to adopt the same functionality in the Windows command shell. ...

replace white spaces with a comma in a txt file in linux

Hi all, I need to edit few txt files (an output from sar) and to convert them into csv files. therefore I need to change every white space (or maybe it's a tab between the numbers in the output) using sed or awk functions (an easy shell script in linux) can anyone help me? every command I used didn't change the file at all (I tried gsu...

Escape Single Quote Characters when Importing to SQLite

Hi everyone. I have a records.txt file like this: INSERT INTO 'blogtitles' VALUES('Kelly's at house'); INSERT INTO 'blogtitles' VALUES('Nice catch!'); When i try to import records.txt into the db: sqlite3 my.db < records.txt It gives an error because of the first line. I have many lines like this in the records.txt file. I need a sed ...

What are some one-liners that can output unique elements of the nth column to another file?

I have a file like this: 1 2 3 4 5 6 7 6 8 9 6 3 4 4 4 What are some one-liners that can output unique elements of the nth column to another file? EDIT: Here's a list of solutions people gave. Thanks guys! cat in.txt | cut -d' ' -f 3 | sort -u cut -c 1 t.txt | sort -u awk '{ print $2 }' cols.txt | uniq perl -anE 'say $F[0] unless $...

How to move part of file to its end

Hi, rpm automatically place a new installed kernel as the first option. However, I want to move it as the last one - to end of the file. Grub configuration file looks like this: default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Fedora (2.6.29.6-217.2.7.fc11.x86_64) root (hd0,0) kernel /vmlinuz-2.6.29....

To count a character in files by Find/Xargs/Sed

How can you count the number of the character < in your files? I am trying to count the number of the character "<" in my files, similarly as in Vim by %s/<//gn I run find * -type f | xargs sed 's/<//gn' I get sed: -e expression #1, char 7: unknown option to `s' This error suggests me that Vim's :s -mode is not like SED. ...