sed

How to extract the name of immediate directory along with the filename?

I have a file whose complete path is like /a/b/c/d/filename.txt If I do a basename on it, I get filename.txt. But this filename is not too unique. So, it would be better if I could extract the filename as d_filename.txt i.e. {immediate directory}_{basename result} How can I achieve this result? ...

I want to use sed to replace every occurrence of /dir with $dir (replace / with $) in every script in a directory

use sed to replace every occurrence of /dir with $dir (replace / with $) in every script in a directory. sed "s#/dir#$dir#g" The $ keeps being interpreted as a function or variable call. Is there a way around this? thanks ...

Joining Line Breaks in FASTA file With Condition in SED/AWK/Perl one-liner

I have a data that looks like this > sq1 foofoofoobar foofoofoo > sq2 quxquxquxbar quxquxquxbar quxx > sq3 paxpaxpax pax What I want to do is to join them into one lines: > sq1 foofoofoobarfoofoofoo > sq2 quxquxquxbarquxquxquxbarquxx > sq3 paxpaxpaxpax I tried this code but fail. sed -e 'te' -e 'H;$!d;:e' -e 'x;/^$/d;s/\n//g' Wh...

Using sed or awk to update a line

I want to open the httpd.conf file and change the LogFormat line with the new parameters. The criterion will be that the line should start with "LogFormat" and end with the word "combined" Here is how I do manually. I want to change the line programatically. vi /etc/httpd/conf/httpd.conf #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Refer...

Sed script to edit csv file Or Python

In our project we need to import the csv file to postgres. There are multiple types of files meaning the length of the file changes as some files are with fewer columns and some with all of them. We need a fast way to import this file to postgres. I want to use COPY FROM of the postgres since the speed requirement of the processing are ...

Why does sed require 3 backslashes for a regular backslash?

I'm curious, why does sed need 3 \ just to recognize one? I'd understand it needing 2, but 3 I don't. EDIT: here's an example on my Windows computer, using Cygwin: echo "sample_input\whatever" | sed "s/\\\/\//" If I don't add 3 backslashes, I get a sed: -e expression #1, char 7: unterminated s' command. ...

Using sed to mass rename files

Objective Change these filenames: F00001-0708-RG-biasliuyda F00001-0708-CS-akgdlaul F00001-0708-VF-hioulgigl to these filenames: F0001-0708-RG-biasliuyda F0001-0708-CS-akgdlaul F0001-0708-VF-hioulgigl Shell Code To test: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/' To perform: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \...

Why sed removes last line?

$ cat file.txt one two three $ cat file.txt | sed "s/one/1/" 1 two Where is the word "three"? UPDATED: There is no line after the word "three". ...

sed or awk multiline replace

Hi guys, I am trying to append formatting to all /* TODO : ... */ tags, but I am having trouble in the multi-line area. I can do single line sed's; but for multiline sed and awk, I don't know. How do I do this? I'm open to either. Here's what I have so far. sed 's/\/\/\*[ \t]*TODO[ \t]*:.*/*\//<span style="color:#aaaaaa;font-weight:bo...

Bash substitution; remove everything after the string

This is probably a very stupid question, but in Bash I want to do the following substitution: I have in some files the line: DATE: 12 jan 2009, weather 20C and I want to change it to DATE: XXXX Using sed I guess I had to say "starting after "DATE:", please remove the rest and insert " XXXX". Is this approach OK and how can...

How can I make SED perform this transformation?

I am trying to get SED to transform the output from a TMS320C55x compiler so that it is parsed correctly by Visual Studio (so that when you click an error/warning it jumps to the location in the source. I have done this successfully with other compilers, but do not use SED often enough for this to be painless, and this time it has defea...

replacing a path with sed

How can I use sed to replace this line char * path_list_[1] = { "/some/random/path" }; with this line char * path_list_[2] = { "lib/foo", "lib/bar" }; in a file named source.c Notes: * The path is really random. * Your solution should only change this line in source.c * I'm only interested in a sed oneliner. You can use this Pyth...

Calculate difference of numbers in two files

Say I have two files where there is one number per line File 1 file 2 0.12 0.11 0.121 0.454 .... .... I want to create file or output difference between each number on to the screen, so that result looks like 0.0099 -0.333 ...... You can use bash/awk/sed ...

sed: toupper a character on a location

This sed "s/public \(.*\) get\(.*\)()/\1 \2/g" will transfor this public class ChallengeTO extends AbstractTransferObject { public AuthAlgorithm getAlgorithm(); public long getCode(); public int getIteration(); public String getPublicKey(); public String getSelt(); }; into this public class ...

bash: filter away consecutive lines from text file

I want to delete from many files each instance of a paragraph. I call paragraph a sequence of lines. For example: my first line my second line my third line the fourth 5th and last the problem is that I only want to delete them when they appear as a group. For example, if my first line appears alone I don't want to delete it. ...

Using a dictionary file with sed

I have a blacklist.txt file that contains keywords I want to remove using sed. Here's what the blacklist.txt file contain winston@linux ] $ cat blacklist.txt obscure keywords here ... And here's what I have so far, but currently doesn't work. blacklist=$(cat blacklist.txt); output="filtered_file.txt" for i in $blacklist; ...

sed and awk one liners

FYI below website is a great place for sed & awk one liners www.readylines.com Hope that helps. ...

Trouble with piping through sed

I am having trouble piping through sed. Once I have piped output to sed, I cannot pipe the output of sed elsewhere. wget -r -nv http://127.0.0.1:3000/test.html Outputs: 2010-03-12 04:41:48 URL:http://127.0.0.1:3000/test.html [99/99] -> "127.0.0.1:3000/test.html" [1] 2010-03-12 04:41:48 URL:http://127.0.0.1:3000/robots.txt [83/83] -> ...

Remove line from a file using a variable line number

Hi Guys, This is probably a simple one to answer, but I'm stuck, so here goes. sed '3d' filename # (or something like that) I'm having trouble trying to use a $VARIABLE instead of the number. Anyone know how to get this to work, or any alternative options? Regards Paul ...

select fields with sed

Hey, Using only grep and sed, is there a way I can tranform the output of ls -l * into this : -rw-r--r-- agenda.txt -rw-r--r-- annuaire.txt Thanks! ...