0
votes
1answer
27 views

Replace negative values in a file with zeros

I want to replace all negative values in a file with zeros. How can I do this in awk? I tried with gsub but gsub(-*, 0) doesn't work... Any ideas? My "code" is awk '{gsub($(!/-/),"0",$2); print $1 ...
2
votes
4answers
55 views

Extract lines based on long list of line numbers

I have a long list of line numbers (35389208) that I do not want in my file. By line number I mean the line in my file (e.g. line 277). My list of line numbers I do not want looks like: 277 278 279 ...
0
votes
1answer
50 views

SED: syntax error at script.pl line 19, near “;$'”

I am using this command to delete multiple occurrences of a line in my script and it just works fine when I run it on the command prompt. However when I use this line in my perl script it throws an ...
2
votes
1answer
109 views

Use perl to do multi-line replacement [closed]

I have to do some replacements in many *.c files. I want to do the replacement like this: original: printf("This is a string! %d %d\n", 1, 2); result: print_record("This is a string! %d %d", 1, 2); ...
3
votes
2answers
439 views

How to comment out multiple line matching a regex using sed or awk

I have a file that contains this: [...] location /static { ... multiple lines ... } [...] location /static/ { ... multiple lines ... } [...] And I want to get: [...] # ...
0
votes
1answer
110 views

Find number in string and replace it

I wrote C++ code and now I want to replace the number in a string by using shell scripts. The part that needs to be replaced: if (random<=90) How I can change the 90 from a shell script? I ...
0
votes
1answer
81 views

Perl or Sed to remove a web virus

I recently ran across a bit of code injected to all of the files on a web site and I need to use perl or sed to remove it across all the files. I am having trouble coming up with the exact pattern ...
0
votes
1answer
301 views

Mass migration of EXIF GPS data (a.k.a. Escape from iPhoto)

I am trying to move my library of photos (over 12000) out of iPhoto for use in Adobe Lightroom and would like to include the GPS data I've added to the photos using iPhoto's in-app feature (This data ...
0
votes
3answers
568 views

Match and remove first and second pattern within xml tags

How can I match and remove first and second pattern within xml tags using sed or awk? Here is the example <data>A78-1-1134-HI-1</data> <data>T78-12-1346-AG-2</data> ...
2
votes
3answers
333 views

matching start of the line in cygwin regexp

I apply sed 's/^ bug*/__/' to ref bug bug ref and get ref __ __ ref The same is responded for perl, perl -ni -e 's/^ bug/__/; print'. Sample file can be downloaded ...
2
votes
2answers
378 views

How to remove three consecutive line feeds in a Makefile rule?

I need to search for and replace three consecutive newline characters in an input file and filter them out of an output file for a makefile rule on Centos 4. I am using GNU sed v4.1.2 and GNU make ...
2
votes
2answers
2k views

perl - translate sed to perl

The following command work fine on Solaris ( delete line only if last character is ":" ) sed -e '/:$/d' < foo > foo.new how to do the same in perl ? ( the reason for that because I not want ...
11
votes
6answers
3k views

Removing ANSI color codes from text stream

Examining the output from perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' in a text editor (e.g., vi) shows the following: ^[[37mABC ^[[0m How would one ...
1
vote
4answers
500 views

sed removal of whitespace

I find that sed often fails to pattern-match whitespace. Consider the following examples: echo 'A B C' | sed 's/[ \t]*//g' ABC echo -e 'A\tB\tC' | sed 's/[ \t]*//g' A B C perl ...
0
votes
1answer
277 views

awk + sed + match complex string

I need useful command to match the string "/pci.../pci.../pci..../scsi..../disk..." with awk or sed? ( I need to put this command in my ksh script ) remark 1 [...] can be any string , and “pci pci ...
0
votes
2answers
84 views

Linux file content replacement issue

I am using Linux Red Hat 5 Enterprise version. For all files in the current directory, I want to replace all occurrences of /foo/goo/zoo (which are contained in file contents) to /a/b/c. Any ideas ...