New answers tagged

1

After the line my @titlewords = split /\s+/, $title; #/ get words add the code to remove the words from the array: my @new; foreach my $t (@titlewords){ push(@new, $t) if $t !~ /^(and|if|the)$/i; } @titlewords = @new;


0

I would leave the history file alone and implement your recording of commands in the prompt_command handler instead. I would also make it write to a private log file then you don't have the conflicts with other usages of the history file or issues with other users accessing /root


2

I know you've already solved your problem, but FYI you could have solved it with a very simple modification to your code : by inverting the sequence you loop over. Using {107..27..-1} (or more concisely {107..27}) would have been enough to solve your problem, since when replacing 30, only the original 30 would have been found, the 27 having not been ...


0

Ok, I think i've got a solution for the double index as well modifying the command of cas. This makes the job: perl -p -e 's/\[(\d+)\]\[(\d+)\]/"[" . ($1) . "][" . ($2+40) . "]"/ge' prova.txt Not sure by the way why I need the . ($1) . (point with blank space).


4

You could also use awk: awk -F '[\\[\\]]' '{if ($2) { sub($2, $2 + 3)}} 1' prova.txt In fact, this can be slightly shortened to: awk -F '[\\[\\]]' '$2 { sub($2, $2 + 3)} 1' prova.txt


3

perl -p -e 's/\[(\d+)\]/"[" . ($1+3) . "]"/ge' dad85.txt This perl one-liner replaces any positive integer number (\d+) inside square brackets with that number incremented by 3. It uses the e regexp modifer to make perl evaluate the replace portion of the s/// operation as an expression. Output: (freqBiasL2[30]) (SatBiasL1[30]) (defSatBiasL2_L1[30]) ...


7

Use perl: perl -pe 's/(?<=\[)(\d+)(?=\])/$1+1/ge' prova.txt Explanation: -p means loop over every line and print the result after every line -e defines the expression to execute on every line s/from/to/ does a simple substition s/(\d+)/$1+1/ge matches one or more digits, captures it into $1, and then the e modifier on the end tells perl that the ...


0

You can iterate column by column working on awk index print field: for i in $(seq $(awk '{print NF}' linux.txt | sort -nu | tail -n 1)); do awk -v field=$i '{print $field}' linux.txt | grep -v "^$"; done > LinuxNewOrder.txt $ cat LinuxNeworder.txt linux-test01 LinuxCV LinuxDF linuxER LinuxWE LinuxXC LinuxPL LinuxSD LinuxAQ Some more explanation: awk ...


2

using combination of awk and grep : awk -v RS=" " '{print}' Linux.txt | grep . > LinuxNewOrder.txt more simpler one, using xargs : xargs -n 1 < Linux.txt > LinuxNewOrder.txt


-2

This might help your problem solved. (Refer: Awk command I want to compare two rows in two files and update the second file if the row matches) Source.txt has following two lines: OldString NewString Before command execution Target.txt has following lines: OldString ==> NewString This is Target File containing OldString now. OldString is to be ...


0

awk -F, -v OFS=, '{ str[$1]+=$2; next } END { for (s in str) { print s, str[s] } }' filename builds an associate array (i.e. keyed by a string rather than an integer) containing the cumulative totals for each string (field 1). When it has read all of the input, it prints out each ...


2

You can do it by adding its path to the PERL5LIB environment variable : export PERL5LIB=/opt/dwimperl-linux-5.20.1-10-x86_64/perl/lib/site_perl/5.20.1


0

How about bash: for i in $(cut -d ',' -f1 FILE | sort | uniq) do echo -n "$i", && echo -n $(grep "^$i," FILE | cut -d',' -f2 | paste -sd+ - | bc) echo $(echo "$i" | grep -E -o ",$") || echo done Or if you're going to miss ,: for i in $(cut -d ',' -f1 FILE | sort | uniq) do echo -n "$i", && echo -n $(grep "^$i," FILE ...


1

Easy in Perl: use a hash to store the running sums. perl -laF/,/ -ne ' $h{ $F[0] } += $F[1]; }{ print "$_,$h{$_}" for keys %h; ' input-file > output-file -n reads the input line by line -l adds newlines to print -a splits each input line into the @F array -F/,/ tells -a to split on commas }{ is the "Eskimo greeting" operator, it separates ...


1

Using sed: sed -i.bak 's#^\(GLOBAL_PATH=/export/\)pop/PLW5$#\1lld/sat#' /var/userTN/applo/* The original file(s) will be backup up with .bak extension, if you don't want backup(s): sed -i 's#^\(GLOBAL_PATH=/export/\)pop/PLW5$#\1lld/sat#' /var/userTN/applo/* Example: $ sed 's#^\(GLOBAL_PATH=/export/\)pop/PLW5$#\1lld/sat#' ...


4

If your perl script produces no other output than the value of $circle, you can use command substitution to store that output in a variable. For example: circle=$(perl perlscript.pl) If the perl script produces other output as well (or not output at all), you'll have to either: extract only the value you want from the output using the usual text ...


-3

Just set an environment variable in perl and your shell will find it. In C you can check your path like this void getPath() { if (getenv("PATH") == NULL) { printf("'%s' is not set.\n", "PATH"); /* Default our path if it is not set. */ putenv("PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc"); } else if (getenv("PATH")) { ...


0

$ perl -ne ' $filename = substr($_,30,2); open $fh{$filename}, ">", $filename unless exists $fh{$filename}; print {$fh{$filename}} $_ ' file $ cat 0A 1111111111111111111111111111110A111111111111111111111111111111 1111111111111111111111111111110A111111111111111111111111111111 1111111111111111111111111111110A111111111111111111111111111111 $ ...


2

For each line you can just use substr($line,30,2) to get the two characters you want. So something like #!/usr/bin/perl use warnings; use strict; open(my $file1,">file1"); open(my $file2,">file2"); open(my $file3,">file3"); while(<>) { my $ch=substr($_,30,2); if ($ch eq '0A') { print $file1 $_; } elsif ($ch eq '0B') { print $file2 ...


13

This perl script builds a hash with words (read one per line from stdin, and/or from any filenames listed on the command line) as keys, and syllable counts as the values. Then it prints the hash keys, sorted by the syllable counts. #! /usr/bin/perl use strict; use Lingua::EN::Syllable; my %words = (); while(<>) { chomp; $words{$_} = ...


1

sed 's/abcd\(X[0-9][a-z]ad\)45das/\1/g' your_file_name should do it.


5

sed does not understand \d. You can use [0-9] or, more generally, [[:digit:]] in its place: $ sed -r 's/.*(X[[:digit:]])(.*)45.*/\1\2/' test.txt X1yad X2fad X3had X4wad X5mad Note that [[:digit:]] is unicode-safe but [0-9] is not.


0

You sed does not understand the special sequence \d. Replace \d with [0-9] or character class [:digit:]: $ cat file.txt abcdX1yad45das abcdX2fad45das abcdX3had45das abcdX4wad45das abcdX5mad45das $ sed -nr 's/.*(X\d)(.*)45.*/\1\2/p' file.txt $ sed -nr 's/.*(X[0-9])(.*)45.*/\1\2/p' file.txt X1yad X2fad X3had X4wad X5mad



Top 50 recent answers are included