New answers tagged

2

There are various ways: call as perl -Ipath script.pl call as PERL5OPT=path script.pl globally set export PERL5OPT=path in .bashrc (affects other scripts too)


2

There are two streams of output from a process that are generally sent to the terminal: standard output (which is bound to file descriptor 1), and standard error (which is bound to file descriptor 2). This allows for easily separated capture of expected output, and error messages or other diagnostic information that is not generally expected to be output. ...


0

Here's 2/3 of the answer, using *nix software tools. file_1_updated: head -n 1 file_1 ; \ { tail -n +2 file_1 | cut -d ',' -f 2 ; \ tail -n +2 file_4 | cut -d ',' -f 1 ; } | \ sort -n | uniq | nl -s ',' | tr -d ' ' Output: nid,vname 1,name1 2,name2 3,name3 4,name8 file_2_updated: head -n 1 file_2 ; \ { tail -n +2 file_2 | cut -d ',' -f 2- ; \ ...


1

You can run this code, Sub SaveSheets() Dim strPath As String Dim ws As Worksheet Application.ScreenUpdating = False strPath = ActiveWorkbook.Path & "\" For Each ws In ThisWorkbook.Sheets ws.Copy 'Use this line if you want to break any links: BreakLinks Workbooks(Workbooks.Count) Workbooks(Workbooks....


2

That's a job for pax. pax is a standard POSIX command; some Linux distributions omit it from the default installation, so you may need to install the package explicitly. You don't get the full power of Perl, just basic sed regex replacement, but that's good enough for your use case. pax -rw -pe -s'|/pars/|/|' -s'|/fts/|/|' -s'|innobase/include|include|' … ...


0

OK, so I managed to get away with plain old sed like this. ls -1 \ storage/{innobase,xtradb}/pars/{pars0grm.cc,pars0grm.y,pars0lex.l,lexyy.cc} \ storage/{innobase,xtradb}/fts/{fts0blex.cc,fts0blex.l,fts0pars.cc,fts0pars.y,fts0tlex.cc,fts0tlex.l} \ storage/innobase/include/fts0[bt]lex.h \ | sed -re 'h; s|/pars/|/|; s|/fts/|/|; s|innobase/...


0

Perl has access to exported shell variables through the %ENV hash. It would probably be much simpler to use that. Something like: $ export repo arch linesToWrite $ perl -0pE 'use strict; my $repo = $ENV{"repo"}; my $arch = $ENV{"arch"}; s|\rsync:\/\/[^\]]+|$ENV{"linesToWrite"}|' I don't understand what you're trying to do with that ...


1

Unix philosophy: one tool does one thing (very well), then combine tools. I suggest that you use the tools you know. The tools that have all the features and options you need and know/master already. So, use cp, rsync, scp or whatever, then use your favorite rename command.


1

Assuming you just want the shell variables $repo $arch and $linesToWrite expanded, put them in double quotes and the rest in single quotes. Quoted strings next to each other make a single string ("a"'b' is ab). (I don't know what you are doing with the backslashes in the substitute command, so I left them, but you probably don't want them). perl -0pE 'use ...


5

The POSIX module includes the strftime function, which allows via strftime(3) conversion specifier characters the desired templating of time: % perl -MPOSIX=strftime -E 'say strftime "[%F %T]", localtime(time)' [2011-02-17 10:55:37] % So in your case make it perl -MPOSIX=strftime -e ... and then printf( ($line=~/^\[\s*(\d+)\.\d+\](.+)/) ? ( "[%s]%s\n", ...


0

When you run that whole nbq ... find ... | sort ..., pipeline, the shell splits the commands up as follows: nbq -P <pool> -q <slot> -c <machine> -J <logfile> --task-name checkdisk find /nfs/disks/test_dir/ -name .snapshot -prune -o -printf '%s %p\n' | sort -nr | head -n 50 | tee log So the only thing that nbq sees is the bit ...


1

$ sed -e '2,$ s/^host_name/\n&/' ravi.txt | perl -n -e 'if (! m/^$/) { chomp; $line .= $_ . ", " }; if (m/^$/ || eof) { $line =~ s/ +/ /g; # merge multiple spaces into one space $line =~ s/, $//; # strip the trailing comma ...


1

I am sure you can do it much easily in awk, but awk doesn't like me much so here is my take on it using everything but the kitchen sink. Assuming that the data is in a file called file1 export output=; while read line; do if [[ "$line" =~ "host_name" ]]; then export output="${output}\n"; fi; export output="${output}, $line"; done < file1 && echo -...


2

In an attempt to give this Q a proper answer, based - on - the - comments (heeding Sobrique's note that parsing XML should really be done with an XML parser): perl -CSD -lne 'print for /\w{63,}/g' input-file-here


3

Your perl script has open CSV2, "<csv2" or die; ... open CSV1, "<csv1" or die; Where are those files located? cron's current directory is the home directory of the user. If the files are in the "newitems" directory, you have to cd there first. Make sure you're not making any other assumptions about the environment in your programs. I find this is ...


1

#! /usr/bin/perl use strict; my %words = (); my $index = 1; # keep track of the order that words were read in while (<>) { chomp; $words{$_} = $index++ } # sort %words hash by value to print words in the same order # that they were seen. foreach (sort { $words{$a} <=> $words{$b} } keys %words) { my $word = $_; $word =~ s/s$//; ...


1

With excessive use of grep's -f (obtain patterns from file) option: grep 's$' input | # output: all lines ending with s sed -e 's/s$//' | # those same entries, minus the s grep -F -x -f input | # the entries whose plurals appear sed -e 's/$/s/' | # the plurals to remove grep -F -x -v -f - input



Top 50 recent answers are included