Tag Info

New answers tagged

1

OK, I think I’ve got it.  Your Source: (?<group>.*/).*\n regex is capturing, in the group group, everything after the Source:  up through the last / on the line.  So, for your example, it is capturing /disk/media/Camera/.  To capture the JPEG image filename, you want Source: .*/(?<group>.*)\n… OK, here we go again.  I believe that you are ...


0

Following Anthon's suggestion to use "uniq"... Remove leading, trailing and duplicate blank lines. # Get large random string. rand_str=; while [[ ${#rand_str} -lt 40 ]]; do rand_str=$rand_str$RANDOM; done # Add extra lines at beginning and end of stdin. (echo $rand_str; cat; echo $rand_str) | # Convert empty lines to random strings. sed "s/^$/$rand_str/" ...


2

Let looking into perl source to more details. In perl.c: case '0': { I32 flags = 0; STRLEN numlen; SvREFCNT_dec(PL_rs); if (s[1] == 'x' && s[2]) { const char *e = s+=2; U8 *tmps; while (*e) e++; numlen = e - s; flags = PERL_SCAN_SILENT_ILLDIGIT; rschar = ...


3

Octal is just like decimal in that 0 == 0, and 0000 == 0, 0 == 000000, etc. The fact that the switch here is -0 may make things a little confusing -- I would presume the point about "the special value 00" means one 0 for the switch and one for the value; adding more zeros is not going to change the latter, so you get the same thing... Up to a point. The ...


0

I think you have to add: my $q = CGI->new(); my $username = $q->param('username'); ... So the whole should look like: #!/usr/bin/perl -wT use strict; use warnings; use CGI; my $q = CGI->new(); my $username = $q->param('username'); print $q->header(); print $q->start_html("Perl page"); print $q->h2("Hello, $username!\n"); print ...


1

AIX's {smd5} format is a non-standard one. It's a minor variant of the *BSD/Linux/Solaris “MD5” (which is the one generated by openssl passwd -1). I wasn't able to find much information about it. There is code contributed to John the Ripper (present in the 1.8.0 jumbo version) that calculates it, in the file aix_smd5_fmt_plug.c. From reading the code, it ...


0

good answer is in Siyuan Ren's comment. Use somehow the command tofrodos


2

Simplify your situation: This is not a VMware install problem, it's a "Why doesn't the system recognize /usr/bin/perl?" problem. Once that's fixed, you should be able to install VMware... at least, you've overcome the first hurdle. So, try: /usr/bin/perl -e 'print "Hello, world\n";' and see what you get. This will be your first clue into the underlying ...


3

If you have gnu parallel installed, you could make a script with just the commands, e.g.: ../perlscripts/v2csv.pl -v -F reach results/Heterogeneous*.vec > ./results/csv/reach.csv ../perlscripts/v2csv.pl -v -F roundTrip results/Heterogeneous*.vec > ./results/csv/RT.csv ../perlscripts/v2csv.pl -v -F downlink results/Heterogeneous*.vec > ...


1

You can try the following syntax: mkdir ./results/csv && (script0 & script1 &) This will run the scripts in the background, not waiting for them to finish. The parentheses introduce a subshell group (so that no script will be run if the mkdir command fails) and the & requests background execution (returning control to the outer shell ...


2

../_Cscripts/v2csv.pl -v -F reach results/Heterogeneous*.vec > ./results/csv/reach.csv & ../_Cscripts/v2csv.pl -v -F roundTrip results/Heterogeneous*.vec > ./results/csv/RT.csv & ../_Cscripts/v2csv.pl -v -F downlink results/Heterogeneous*.vec > ./results/csv/DL.csv & ../_Cscripts/v2csv.pl -v -F clusters results/Heterogeneous*.vec > ...


5

You need to use \r, not ^M to match carriage return characters. ^M has removed all M characters at the beginning of the line, so you may want to check your file is still OK...


6

Perl needs a \r as well. perl -pi -e 's/^M//g' file1 ^^ - should be \r Although actually, you probably just want to stick with line endings. perl -pi -e 's,\r\n,\n,g' file1 Although actually - you don't need perl for this. sed is perfectly capable: sed -i.bak -e 's,\r\n$,\n,g' file1


1

Since you indicate that you are aware that this will break your XML, you can do what you want with one of these: Perl perl -ne 'print unless m#^<units>.*</Networks>$#' file.xml perl -ne 'm#^<units>.*</Networks>$# ? next : print' file.xml awk awk '!/^<units>.*<\/Networks>$/' file.xml sed sed ...


2

You can do this with perl, using the excellent XML::Twig module. Assuming I've understood you correctly, the basics task is copying the 'verse content' element from one file, and 'everything else' from another file, and making a new file. So: #!/usr/bin/perl use strict; use warnings; use XML::Twig; my %nkjv_content; sub extract_content { my ( ...


3

Do not use regular expressions to parse XML. It's an excellent way to create brittle code, because there's a bunch of perfectly valid things you can do with XML which will break a regex. Things like reformatting the XML in entirely valid ways (such as 'pretty printing' it in a nested/indented form) will break your code. Instead I would suggest - use an XML ...


2

Try this: perl -i -pe 's|^<units>.*</Networks>$||' /my/filename Note that if you have leading or trailing space in the line you will need this instead: perl -i -pe 's|^ *<units>.*</Networks> *$||' /my/filename I uesd pipe as a separator rather than slash to avoid unnecessary escaping.


2

The other answers give solutions for sed and awk. If your sed and awk don't support multibyte characters, there's still a good chance that your bash does support them, so here is a pure-bash solution. First we choose a random number between 0 and the length of the string $a, inclusive, so that the string $b can be inserted between any two characters of $a, ...


0

In Perl (suitable for a shell script): perl -CSA -e '$_=shift; substr($_,int(rand(1+length)),0,shift); print' "$a" "$b" Note the 1+length different positions here: at the start of the string and after each character. ETA: And yes, the -CSA specifies that command line arguments and standard output (and other standard file handles) use UTF-8 (multibyte).


0

Any answer will depend on what you can actually know about your input. If you know you want the second bar3 surrounded by <font>, you could do: perl -pe 's#(.*bar3.*)(bar3)#$1<font style=BACKGROUND-COLOR:red>$2</font>#' file or sed 's#\(.*bar3.*\)\(bar3\)#\1<font style=BACKGROUND-COLOR:red>\2</font>#' file or, with GNU ...


0

I summarised Stéphane Chazelas' answer: ${1:+"$@"}' test if $1 null or unset ${1+"$@"}' test if $1 unset so if use second one with parameter "", that means $1 is null,but it doesn't test weather it is null or not,it just see it have already setted neverless it it empty or not,so it will expand $@,but you use ${1:+"$@"}' with "",it will not expand ...


3

The first issue is that $directory contains slashes which are also being used as the delimiter for the substitution operator (s///). Basically, if $directory is /home/je_b, what Perl sees is: perl -i -pe "s/foo//home/jb/ if \$. == 4" file.txt It takes the / of /home as the second / of the s/// operator. The simplest solution is to use a different ...


1

To access the environment variable in Perl you can use $ENV{var1}. To do this you can export the variable, this will mean the variable is set until you unset it: export var1=newstring perl -i -pe 's/(keepme=)(.*)/$1$ENV{var1}/ if $.==1' ../file.txt Alternatively if you only want to set the variable to be used by the Perl command when you execute ...


1

Starting from your first attempt, you want ${var1} expanded by the shell, and all other $ variables protected from it (so that Perl expands them instead): perl -i -pe "s/(keepme=)(.*)/\$1${var1}/ if \$. == 1" ../file.txt The double quotes, rather than single quotes, make it so that Perl receives newstring instead of the variable name, and escaping the ...


0

A simple cut solution: $ cat test01 |cut -d "(" -f2 | cut -d ")" -f1


1

The following should work on any system with Perl: perl -pe 's/(>.*)(bar3)(.*<\/a>)/$1<font style=BACKGROUND-COLOR:red>$2<\/font>$3/' At least it does the right thing on your example file; the regexp in s/regexp/replacement/ asks to match bar3 between > and </a>, as you asked, but if your real-world HTML input is more complex ...


0

This solution requires the GNU version of awk... awk '{ print gensub(/(>.*)(bar3)(.*<\/a>)/,"\\1<font style=BACKGROUND-COLOR:red>\\2</font>\\3","g") }' yourfile.html


1

(Edited solution due to feedback about actual requirements...) It's probably easier to understand and implement if you perform it in four steps; replace \n\n by some unused [control] character (say \a), add an \a at the front of a line with an \a, then delete all \n, and finally replace the \a by \n again. (Define a vim macro if you need that replacement ...


3

New GNU sed (with parameter -z) do it one pass: sed -z 's/\n\(\n\|[A-Z0-9][)a-z]\)/ \1/g' DATA


1

I like playing with regular expressions but truly I don't feel like I am a master of it. I would do what you want in 2 steps: $ perl -i.bak -0pe 's/\n([A-Z])/ \1/g' DATA $ less DATA 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b And now just remove empty lines, for example with sed or flush-lines function ...


1

Using awk + sed perhaps? For: $ cat quiz 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b Run $ awk NF=NF RS= OFS=' ' quiz | sed 's/\([a-z]$\)/\n\1/' 23. Lorem A) he B) ha C) hu c 2. Ipsun yes right to write something here? A) Ok B) No C) yes b


0

The syntax for a negative lookahead in vim is like this: :s/\n\n\@!//gN Where N is a number of lines. In perl, it would be: s/\n(?!\n)// However, I think you'll find that's not exactly what you are trying to do, since in your example output, c and b are both on a line of their own. If you replace all newlines not followed by another newline, they ...


0

I don't have time for a full answer right now. I'll try to come back to it later. For now, I'll just point out the immediate problems. 1) You can't use a blank as a field separator and as a value at the same time. If your values are fixed length (one column each), then you can use that to your advantage. If you could just set missing values to zero, that ...


0

Try awk -v pattern="bar3" 'match($0, pattern){ beg = index( $0, ">") content = gensub(/<.*$/, "", "", gensub(/^[^>]+>/, "", "", $0)) beg_str = index( content, pattern) if (match (content, pattern)) { print substr($0, 0, beg) substr(content, 0, beg_str - 1) "<fontstyle=BACKGROUND-COLOR:red>" substr(content, beg_str, ...


3

awk -F'|' -v p='Field3' -v r='T' ' NR==1{ for (i=1;i<=NF;i++) if ($i==p) f=i print next} $f=r ' If you like to format it to use like script.awk save it like: #!/usr/bin/awk -f BEGIN{ OFS=FS="|"} NR==1{ for (i=1;i<=NF;i++) if ($i==p) f=i print next} $f=r ...


1

The standard trick for this kind of problem in Awk is to use an associative counter array: awk '{ print $0 "\t" ++count[$1] }' This counts the number of times the first word in each line has been seen. It's not quite what you're asking for, since Apple_1 1 300 Apple_2 1 500 Apple_1 500 1500 would produce Apple_1 1 300 1 ...


1

With export LC_ALL=C I actually got rid of the warning. This is more of a workaround (as LC_ALL is also strongly discouraged), but my guess is the reason for this behaviour lies in assumptions nix makes about locales on the system which don't apply on openSUSE.


0

I had run into the same issue while following blogged instructions. It turned out, the command I was using was incorrectly formatted. My mistake, pkg_add -lv software the tags after - should have been an uppercase I and a lower case v instead of a lowercase L and a lowercase v. This occurred through a misinterpretation with the fonts used on the instructions ...



Top 50 recent answers are included