Tag Info

Hot answers tagged

9

You can use rsync to do this: $ rsync -abviuzP src/ dest/ -a archive mode; equals -rlptgoD (no -H,-A,-X) -i turns on the itemized format, which shows more information than the default format -b makes rsync backup files that exist in both folders, appending ~ to the old file. You can control this suffix with --suffix .suf -u makes rsync transfer skip ...


7

I don't think you can do it with join alone. You could do: join -t, -a1 -a2 -o0,1.2,1.3,1.4,1.5,2.2,2.3,2.4,2.5 -e MISSING 1.txt 2.txt | perl -F, -lape '@F[1..2]=@F[5..6] if $F[1] eq "MISSING"; $_=join",",@F[0..4],@F[7..8]' -p: use a line by line reading loop like in sed/awk -a, -F,: like awk, split the lines into fields (into the @F ...


5

I'll assume that extra field from the n lines of file2 should be appended to the last n lines of file1: awk -F, -v OFS=, 'FNR==NR {a[FNR]=$3; next} {print $0, a[FNR]}' <(tac file2) <(tac file1) | tac paste -d, <(tac file1) <(cut -d, -f3- <(tac file2)) | tac These solution add a trailing comma to the first line. You can remove it by ...


5

This is definitely feasible. Many of us were running mixed, load-balanced broadband configs for corporate years ago and they worked really well. Many probably still do! You can do it in a number of ways, including using iptables rules and/or iproute2 (ip(8) command) to setup policy routing. The load balancing is not done at the packet level, but at the ...


5

You can use bash scripting, but for compression etc. it relies on other programs. You might be better of with Python, or any other scripting language which can generate CSV files for you (although CSV syntax is not necessarily difficult to generate), and that can do the concatenation and compression. Given this directory of files (all different length, but ...


5

awk ' NR==FNR {vals[$1] = $2 " " $3 " " $4; next} !($1 in vals) {vals[$1] = "0 0 0"} {$(NF+1) = vals[$1]; print} ' file2 file1 TABLES REF-IO HEAD-IO DIFF-IO REF-SELECT HEAD-SELECT DIFF-SELECT test 200 500 -300 5 7 -2 exam 2 3 -1 0 7 -7 final 2 1 1 12 6 6 mail 4 2 2 0 0 0 TOTAL 208 506 -298 20 23 -3


5

You can use the bedup utility to de-duplicate the identical files. Once you've installed it, usage is fairly simple: # bedup dedup /path/to/btrfs You may need to set your snapshots writable (btrfs property set -ts /path/to/snapshot ro false) so it can de-duplicate them. You can change them back afterwards. Note that depending on how many files you have, ...


4

What implementation of join are you using? With join (GNU coreutils) 5.97, I can use [0 1021] ~/temp/jointest % join -a1 -a2 jointest1.txt jointest2.txt a 1 10 b 2 11 c 12 d 4 13 e 5 and the "plain" join works, too (but omits c and e). There is an -e option which supposedly lets you choose the marker for empty fields, but it appears to be broken in my ...


4

In awk, preserving empty lines, assuming the file is well formatted, but logic could be added to check the file: awk -v RS="" '{for(i=1; i<=NF; i++) a[i]=$i getline for(i=1; i<=NF; i++) print a[i] " " $i print ""}' file


4

<input sed -nr '/^[A-Z]{4}$/,/^$/w out1 /^[0-9]{4}$/,/^$/w out2' paste -d' ' out1 out2 |sed 's/^ $//' or, in a single step, without temp files paste -d' ' <(sed -nr '/^[A-Z]{4}$/,/^$/p' input) \ <(sed -nr '/^[0-9]{4}$/,/^$/p' input) | sed 's/^ $//' The last sed step removes the delimiter on the blank lines, ...


4

I usually use paste from coreutils for this sort of thing: paste -d'\n' file1 file2 file3


4

Use vimdiff if you like vim. Otherwise, diffuse works great as well.


4

You don't need patch for this; it's for extracting changes and sending them on without the unchanged part of the file. The tool for merging two versions of a file is merge, but as @vonbrand wrote, you need the "base" file from which your two versions diverged. To do a merge without it, use diff like this: diff -DVERSION1 file1.xml file2.xml > merged.xml ...


4

The PyPdf library makes this sort of things easy if you're willing to write a bit of Python. Save the code below in a script called pdf-cat-even (or whatever you like), make it executable (chmod +x pdf-cat-even), and run it as a filter (./pdf-cat-even a.pdf b.pdf >concatenated.pdf). You need pyPdf ≥1.13 for the addBlankPage method. #!/usr/bin/env python ...


4

If you don't mind the order of output: $ awk -F',' 'NF>1{a[$1] = a[$1]","$2}END{for(i in a){print i""a[i]}}' file jkl, words and numbers, words and numbers, words and numbers, words and numbers abc, 12345, 56345, 15475, 123345 ghi, something else, something else, something else, something else def, text and nos, text and nos, text and nos, text and nos ...


3

As far as I know, there isn't any universal way; it depends on which version control system you are using, e.g.: Mercurial uses a setting in .hgrc. git uses merge.tool configuration, as told in a comment. for svn, you specify in /etc/subversion/config.


3

The first step is to produce a pdf file with an empty page. You can do this easily with a lot of programs (LibreOffice/OpenOffice, inkscape, (La)TeX, scribus, etc.) Then just include this empty page where needed: pdftk A.pdf empty_page.pdf B.pdf output result.pdf If you want to do this automatically with a script, you can use e.g. pdftk file.pdf ...


3

With emacs use rectangle operations to cut the text lines and paste them before the numerical lines.


3

One way using perl: Content of script.pl: use warnings; use strict; ## Check arguments. die qq[Usage: perl $0 <input-file>\n] unless @ARGV == 1; my (@alpha, @digit); while ( <> ) { ## Omit blank lines. next if m/\A\s*\Z/; ## Remove leading and trailing spaces. s/\A\s*//; s/\s*\Z//; ## Save ...


3

This is a useful1 use of cat: $ cat File1 File2 > CombinedFile Footnotes: 1. As opposed to the useless use of cat


3

Yes - bash scripting will be able to meet the requirements. But you should use whatever scripting language you are comfortable with. python, perl are other possibilities.


3

using just awk: awk -F, -v OFS=, ' BEGIN {m = " MISSING"} # process file1 NR == FNR {lines[$1] = $0; next} # process file2 { added[$1] = $4 OFS $5 if (!($1 in lines)) { $4 = m $5 = m lines[$1] = $0 } } # print the combined output END { for (id in lines) ...


3

The 'x' file: FNR==1 { ++FILENO } { T[$1]++ X[$1,FILENO]=$2 } END { print "type\tvalue1\tvalue2\tdifference" for(t in T) print t"\t"X[t,1]+0"\t"X[t,2]+0"\t"0+X[t,1]-X[t,2] } The run: $ awk -f x file1 file2 type value1 value2 difference viewer 23 2990 -2967 remark 2 240 -238 test 27 0 27 ...


3

Another awk solution: $ awk ' FNR==NR { a[$1] = $2; c[$1] = $1; next; } { b[$1] = $2; c[$1] = $1; } END { printf "type\tvalue1\tvalue2\tdifference\n"; for(i in c) printf "%s\t%d\t%d\t%d\n", i, a[i], b[i], a[i]-b[i] }' file1 file2 type value1 value2 difference remark 2 240 -238 test 27 0 27 ...


3

Assuming you're talking about merging 3 partitions into 1 with all the original data intact I do not believe you'll be able to merge these partitions, as they are. There is not enough unused space on any of the partitions that can contain the other partitions' used space. You could shuffle them around and maximize the free space so that it's on 1 of the 3 ...


3

This should do: paste file_1 file_2 file_3 file_4 If you want pretty printing (given that the number of lines are same for all the files), then: paste 1 2 3 4 | column -t


2

If the entries are in order, Split the input into alphabetic entries and numeric entries, using grep: grep "[[:alpha:]]\+" < file > alpha grep "[[:digit:]]\+" < file > digit Join the two resulting files, alpha and digit, using paste: paste alpha digit (you can add -d " " so it uses a space instead of a tab)


2

Try the following: > join -e- -a1 -a2 jointest1 -o 0 1.1 1.2 2.1 2.2 jointest2 a a 1 a 10 b b 2 b 11 c - - c 12 d d 4 d 13 e e 5 - - or > join -e- -a1 -a2 jointest1 -o 0 1.2 2.2 jointest2 a 1 10 b 2 11 c - 12 d 4 13 e 5 - I'm not sure if/how it is possible to achieve the same without the -o option. The -o option says: first print the join field, ...


2

Build raw original and raw target values without settings: sed "s/=.*//g" file_original.ini > file_original.raw sed "s/=.*//g" file_target.ini > file_target.raw I assume that target will have more options than the original. Build the difference: grep -vf original.raw target.raw > newvals.dat Add the new Values: cp -p file_original.ini ...


2

i wrote a little perl script, that do this #!/usr/bin/perl do { open($fh[$_], "<$ARGV[$_]") or die("'$ARGV[$_]' does not exist") } for(0..$#ARGV); for($i=0;;$i++) { $j=$#ARGV+1; $fh = $fh[$i%$j]; if ( $_ = <$fh> ) { print $_; } else { $end |= 2**($i%$j); } if($end == (2**($j))-1) { last; } } ...



Only top voted, non community-wiki answers of a minimum length are eligible