New answers tagged perl
0
votes
convert CSV to XLS file on linux
I was not able to use ssconvert or unoconvert, which is the successor of unoconv and the smaller alternative to libreoffice --headless. Finally I found a nice single binary without any dependencies ...
0
votes
How to deal with CRLF, CR line endings
Using Raku (formerly known as Perl_6)
If the OP believes the problem to be Unicode-based, passing through a Raku script might help, since Raku handles UTF-8 by default:
~$ cat dos2unix.raku
my $fh1 = ...
1
vote
Remove hostnames from URL with sed/awk
Using any sed:
$ sed 's:[^/]*//[^/]*::' file
/
/
/blog/
/blog/
/blog/
/blog/
/blog/
/blog/
/cases/page/4/
/cdn-cgi/challenge-platform/h/g/cv/result/7c9123dc38da6841
/cdn-cgi/challenge-platform/h/g/...
1
vote
Remove hostnames from URL with sed/awk
This is fairly easy to do with linux coreutils:
cut -d '/' -f 3- somefilewithyoururls.txt | sed 's/^/\//'
Cut everything after the third /, then replace the start of the line with a /. No need for ...
3
votes
Accepted
Remove hostnames from URL with sed/awk
With perl:
perl -pe 's|^([^/:]+:)?//[^/]*||' < your-file
Would remove an optional scheme (to take care of both http://host/path and //host/path) followed by // followed by all the characters ...
0
votes
Change file name based on contents
Assuming the files start with two lines in the indicated format, and we have their names on the command line, a TXR program to calculate the rename looks like this:
$ txr data.txr data
rename data -&...
-1
votes
what does syntax .= means in perl
Was your original code example Perl(5), or actually Perl6, a.k.a. Raku?
In year 2000, the Perl folk announced an ambitious re-write to the Perl language, then currently at version 5.6.0. The new ...
1
vote
How to replace the contents of out.txt with in.txt in a third file?
Using any awk in any shell on every Unix box:
$ cat tst.awk
FILENAME == ARGV[1] { old = old $0 ORS }
FILENAME == ARGV[2] { new = new $0 ORS }
FILENAME == ARGV[3] { rec = rec $0 ORS }
END {
lgth = ...
0
votes
How to replace the contents of out.txt with in.txt in a third file?
If your shell does support <() (like zsh, ksh, bash), you can insert markings between the files (here: MARK) to separate them and use any POSIX sed:
sed -e 'H;1h;$!d;x;:L
s/^\(.*\)\(MARK\n\)...
5
votes
How to replace the contents of out.txt with in.txt in a third file?
With perl:
perl -0777 -e '$out = <>; $in = <>; $_ = <>; s/\Q$out\E/$in/g; print
' out.txt in.txt main.txt > new-main.txt
Should work whatever characters or non-...
0
votes
How to deal with CRLF, CR line endings
This pipeline will convert CR characters or CR/LF sequences to LF
tr '\r\n' '\n\r' | sed 's/^\r//g' | tr '\r' '\n'
3
votes
How to deal with CRLF, CR line endings
perl -pi -e 's/\r\n?/\n/g' your-file
Would turn CR characters optionally followed by a LF to LF, similar to what mac2unix or dos2unix -c mac would do.
Or:
perl -pi -e 's/\r\n?/\r\n/g' your-file
To ...
Top 50 recent answers are included
Related Tags
perl × 1329awk × 447
sed × 409
text-processing × 339
linux × 172
bash × 147
regular-expression × 131
shell-script × 129
grep × 79
shell × 73
scripting × 66
python × 57
files × 31
debian × 27
centos × 26
rename × 26
command-line × 25
ksh × 24
cpan × 20
solaris × 18
csv × 18
find × 16
rhel × 14
apache-httpd × 14
xml × 14