Tag Info

Hot answers tagged

8

You have a space after \1 in your replacement, just remove that and you should be good perl -i -p -e "s/^(password[]*=[ ]*).*$/\1$passwd/" config.properties ^ Removed space here


6

That's a typical job for tr: LC_ALL=C tr '\0-\10\13\14\16-\37' '[ *]' < in > out In your case, it doesn't work with sed because you're in a locale where those ranges don't make sense. If you want to work with byte values as opposed to characters and where the order is based on the numerical value of those bytes, your best bet is to use the C locale. ...


3

The 3pm section is not used anymore. It is defined as manual pages concerning modul packages of perl in an old version of the Debian Perl Policy, noteably in version 1.2. Here is a site where you can read that old deprecated policy (see §3.1 and §1.4). In the latest Debian Perl Policy it is defined in §2.4 that module manual pages should be installed in ...


3

Perl one-liner: perl -pe's/\[gene=([^\]]*)\K\]/$h{$1}++?"$h{$1}]":"]"/e' yourfile Explained: -p: execute the code for each line of the file (stored in $_) and print $_ at the end. -e: code. s/regex/replacement/e: Match regex and replace it with replacement on $_. The regex: /\[gene= # match [gene= ([^\]]*) # match anything but "]" and put it a ...


2

sed -n '/-\{10,777\}/,/^\s*Table:/p' LaTeX.doc If you wants newline after each table: sed -n '/^\s*Table:/G;/-\{10,777\}/,/^\s*Table:/p' LaTeX.doc or sed '/-\{10,777\}/,/^\s*Table:/! d;/^\s*Table:/G' LaTeX.doc


2

I'll edit this if you update the question but I think you're looking for something like this: perl -007lne '@F=(/-{7,}.*?Table:.*?\n(?=\n)/gsm); print join "\n", @F' file.tex Explanation -007 : slurp the entire file -lne : add a new line to each print call, process the input file, and run the script given by -e. @F=(/pattern/gsm) : save all matches of ...


2

Base on your output, I offer some points to improve your regex: You can match explicit at beginning of line, using ^ If you don't use the match groups, then you don't need parentheses or using non-capturing group ?: \s includes \t, so you only need \s. The final regex can be m/^(?:[+-]?\d+\.\d+)\s+(?:[+-]?\d+\.\d+)/


2

Perl solution, suitable for smaller files that can fit into memory. For larger files, you'd need to process the file twice. I assumed the input files are tab separated. The %empty hash keeps the list of indices of the empty columns. If a column is populated, it's removed from the hash. So, once the whole file is saved into the @array, the %empty contains ...


2

As @cuonglm said, * means 0 or more. Since you;ve tagged this with Perl, I assume you're using Perl's regex engine which means you can use +: 1 or more. So, the substitution you're after would be one of: Match alphanumeric characters or underscores: s/\w+&\w+/\$$&\$/g Match letters only (note the i which makes the match case insensitive): ...


2

The following should work: perl -pe 's/([0-9.e-]+)/$1 == 0 ? $1 : .001 + $1/ge' < input.txt > output.txt -p process the file line by line s/patern/replacement/ is a substitution. [0-9.e-]+ matches one or more of the given characters, i.e. the numbers () remembers each number in $1 /g applies the substitution globally, i.e. as many times as needed ...


2

Using sed: sed -r 's/(.*[a-zA-Z]{4}\-)([0-9]{4})/\1aaaa/g'


1

Simply: perl -i.bak -pe 's/([0-9.e-]+)/$1 == 0 ? $1 : .001 + $1/ge if 123..345' input.txt -i.bak make perl edit file in-place and make a backup file input.txt.bak (I invite you to read this question) if 123..345 using flip-flop operator, emulate line-range operator of sed, awk.


1

You didn't ask for ruby, but this is pretty fun: ruby -rcsv -e ' columns = CSV.read(ARGV.shift, :col_sep => "\t").transpose trimmed = columns.select {|col| col if col[1..-1].find {|elem| not elem.nil?}} trimmed.transpose.each {|row| puts row.join("\t")} ' file produces col1 col2 col4 col6 1 2 3 43 1 3 ...


1

I found a solution using perl substring function echo leng-1323-006|perl -lpe 'substr($_, 5, 5) = "";' return correctly leng-006 I hve removed from position 5 the 5 bad characters include the -


1

POSIXly: $ sed -e 's/-[^-]*-/-/' file leng-001 leng-002 leng-004 leng-005 leng-006


1

it matches lines that begin with two optionally signed numbers having decimal parts, with said numbers separted by ascii whitespace. it seems optimal and clear as it stands.



Only top voted, non community-wiki answers of a minimum length are eligible