Tag Info

Hot answers tagged

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

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

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

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


4

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 ...


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

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

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


3

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 ...


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

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

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 ...


2

Another Python version that does not need to read all files into memory at once: paddy$ more f[123].tmp :::::::::::::: f1.tmp :::::::::::::: line1 file1 line2 file1 line3 file1 :::::::::::::: f2.tmp :::::::::::::: line1 file2 line2 file2 line3 file2 line4 file2 :::::::::::::: f3.tmp :::::::::::::: line1 file3 line2 file3 line3 file3 line4 file3 line5 file3 ...


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; } } ...


2

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 ...


2

merge(1) is probably nearer to what you want, but that requires a common ancestor to your two files. A (dirty!) way of doing it is: Get rid of the first and last lines, use grep(1) to exclude them Smash the results together sort -u leaves a sorted list, eliminates duplicates Replace first/last line Humm... something along the lines: echo ...


2

You can use join for this. First we have to sort both files using the 2nd column as key: $ sort -t' ' -k 2,2 a > as $ sort -t' ' -k 2,2 b > bs Resulting in: $ cat as 873 1.1.1.1 1108 78.2.204.174 1257 78.2.8.181 1033 99.99.99.10 $ cat bs test7 1.1.1.1 p10 test8 78.2.204.174 p4 test1 78.2.8.181 p6 test2 99.99.99.10 p9 Then the actual join: $ ...


2

If I understand your question correctly you have the following: $ echo -e "line1\nline2\nline3\n" line1 line2 line3 $ And you want this: line1line2line3 So you should only need to remove the blank lines. A command like this should do it: $ echo -e "line1\nline2\nline3\n" | paste -s -d '' line1line2line3 I'm not sure where your output is being kept, ...


1

Another approach would be to simply remove the new lines from your file: echo $(tr -d '\n' < file) > newfile I am using the echo to insert a final new line, if you dont even want that just run tr -d '\n' < file > newfile


1

Gilles' answer worked for me, but since i have to merge many files it's more convenient if i can read their names from a text file. I've slightly modified Gilles' code to do just that, maybe it would help someone else: #!/usr/bin/env python # requires PyPdf library, version 1.13 or above - # its homepage is http://pybrary.net/pyPdf/ # running: ...


1

If I understood your requirements, you want to merge all the flux data for one point in fluxes_lat_long with the format 01 01 Fluxes total_fluxes_for_Jan_1_over_30_years 01 02 Fluxes total_fluxes_for_Jan_2_over_30_years ... If that's the case, here's a Perl script that should help: #!/usr/bin/perl use strict; use warnings; my @files = glob ...


1

I would use sort -u fluxes_*_lat_long > fluxes_lat_long`, it is by far the simplest solution. EDIT: use in a script for file in $(ls -1 fluxes_20*_*_*) ; do export ll="$(echo $file |cut -d _ -f 3,4)" # extract lat & long echo "sort -u fluxes_*_$ll" "> fluxes_$ll" # create sort instruction done | uniq | sh


1

I think you are asking that given files: fluxes_2000_10_10 fluxes_2001_10_10 fluxes_2003_10_10 and fluxes_2000_20_10 fluxes_2001_20_10 fluxes_2003_20_10 You create a "total" file for each of the above files at latitude 10_10 and then 20_10 etc. In which case: bash$ for lat in $(ls -1 fluxes_* | sed 's/fluxes_[0-9]*_\([0-9]*_[0-9]*\)/\1/' ...


1

Assuming by "native" you mean "commonly installed with the base system", then no, there isn't a specific tool for that, but it's easy enough to create a script of your own. #!/bin/sh for f in "$@"; do b=$(basename "$f") # Grab any numeric suffix n=${b##*[!0-9]} # Default to 0 if there is no suffix case n in *[!0-9]* | '' ) n=0;; esac ...


1

You could also use LaTeX to do this (though I'm aware it's probably not what you want). Something like the following should work: \documentclass{book} \usepackage{pdfpages} \begin{document} \includepdf[pages=-]{A} \cleardoublepage % Make sure we clear to an odd page \includepdf[pages=-]{B} % This inserts all pages. Or you can specify specific pages, a ...


1

One way using awk: $ awk 'NR==FNR{a[$2]=$1 FS $3;next}{print $0 FS a[$2] }' file2 file1 873 1.1.1.1 test7 p10 1033 99.99.99.10 test2 p9 1108 78.2.204.174 test8 p4 1257 78.2.8.181 test1 p6 The file f2 is loaded into an array where the 2nd field is the index and the value of the array is combination of 3rd and 4th fields of file2. When file1 is processed, ...


1

Create a file mylist.txt with all the files you want to have concatenated in the following form: # this is a comment file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' Then you can encode your files with: ffmpeg -f concat -i mylist.txt -c copy output Edit: You may need to compile ffmpeg from source to get a recent ...



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