As of May 31, 2023, we have updated our Code of Conduct.

New answers tagged

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 ...
mgutt's user avatar
  • 347
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 = ...
jubilatious1's user avatar
  • 2,129
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/...
Ed Morton's user avatar
  • 28k
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 ...
markgraf's user avatar
  • 2,830
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 ...
Stéphane Chazelas's user avatar
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 -&...
Kaz's user avatar
  • 7,080
-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 ...
jubilatious1's user avatar
  • 2,129
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 = ...
Ed Morton's user avatar
  • 28k
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\)...
Philippos's user avatar
  • 13k
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-...
Stéphane Chazelas's user avatar
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'
roaima's user avatar
  • 104k
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 ...
Stéphane Chazelas's user avatar

Top 50 recent answers are included