Tag Info

New answers tagged

1

There are many ways of doing this. The simplest are probably awk and perl: GNU gawk. If you have a relatively recent version of gawk installed, you can do inline editing like this: gawk -i inplace -F"|" -vOFS="|" '$2=="Orange"{$2="Orange_Edit"}1;' file The -i inplace tells gawk to edit the file inplace, the -F"|" sets the field separator to | and the ...


2

You can use perl: $ perl -i.bak -F'\|' -aple 's/Orange/Orange_Edit/ if $F[1] eq "Orange"' file or safer version: $ perl -i.bak -F'\|' -aple '$F[1]=~s/^Orange$/Orange_Edit/; $_=join "|",@F' file


2

You could do it in 2 steps with awk like awk '{$2="VAL";print}' input_file > temp_file mv temp_file input_file That will split the input file on white space, substitute the value in the second column (use any other number than 2 for different column) so it will now be "VAL". Unless you change it with OFS the output field delimiter will be a space. If ...


2

i=0 { paste res.? res.?? res.??? while paste ./res."$((i+=1))"[0-9][0-9][0-9] do :; done; } >outfile I don't think this is as complicated as all that - you've already done the hard work by ordering the filenames. Just don't open all of them at the same time, is all. Another way: pst() if shift "$1" then paste "$@" fi set ...


1

Given the amount of files, line sizes, etc. involved, I think it will surpasses the default sizes of the tools (awk, sed, paste, *, etc) I would create a small program for this, it would not have 10,000 files open, nor a line of hundred of thousands in length (10,000 files of 10 (max size of line in the example)). It only requires an ~10,000 array of ...


8

If chaos' answer isn't applicable (because you don't have the required permissions), you can batch up the paste calls as follows: ls -1 res.* | split -l 1000 -d - lists for list in lists*; do paste $(cat $list) > merge${list##lists}; done paste merge* > final.res This lists the files 1000 at a time in files named lists00, lists01 etc., then pastes ...


10

If you have root permissions on that machine you can temporarily increase the "maximum number of open file descriptors" limit: ulimit -Hn 10240 # The hard limit ulimit -Sn 10240 # The soft limit And then paste res.* >final.res After that you can set it back to the original values. A second solution, if you cannot change the limit: for f in ...


2

Try to execute it on this way: ls res.*|xargs paste >final.res You can also split the batch in parts and try something like: paste `echo res.{1..100}` >final.100 paste `echo res.{101..200}` >final.200 ... and at the end combine final files paste final.* >final.res


0

The new edited script it's ok but stops on a new line here is the error root@localhost:~/python# ./compare.py input1.txt input2.txt output.txt Traceback (most recent call last): File "./compare.py", line 46, in <module> for row in csvReader: File "/usr/lib/python3.2/codecs.py", line 300, in decode (result, consumed) = ...


0

You could use sqlite for joining your data: $ sqlite3 <<EOT .mode csv CREATE TABLE file1 (A11,A12,A13,A14,A15,A16,A17,A18,A19,A110,A111); CREATE TABLE file2 (B11,B12,B13,B14); .import file1 file1 .import file2 file2 SELECT DISTINCT file1.*, ifnull(file2.B14,"NOACT") FROM file1 LEFT JOIN file2 ON abs(julianday(file1.A11) - julianday(file2.B11))*86400.0 ...


0

The following script should do what you are looking for in python: #!/usr/bin/env python3 import sys import csv import bisect import re timeRange = 1 # seconds # Timestamps should match the following regex timestampRegex = re.compile('[0-9]*:*[0-9]*:[0-9][0-9]\.*[0-9]*') # Convert the time from a string 'hh:mm:ss' to a float def timeToFloat(time): # ...


2

Possible solution with awk (I will edit if needed because it is a little unclear from your question what are exact requirements): awk 'FILENAME == ARGV[1] { m[$2,$3] = 0; z[$2,$3] = $5; next; } FILENAME == ARGV[2] { if (($2,$3) in m) { m[$2,$3] = 1; z[$2,$3] = $5 " " z[$2,$3]; } next; } { if (($2,$3) in m && ...


3

To select shared lines in all files you can use grep (out.txt) grep -ho ' [0-9] [a-z] ' file3 | grep -Fof - file2 | grep -Ff - file1 select operatable field (as variant cut -d' ' -f3,4 file3) and use it to search it in next file2 and file1. As usual for joining 2 file use join command (surprise!) (out2.txt) join -j 3 <(sort -k3,4 file1 | sed 's/ ...


3

You might want to check this site about diff3 with this program you can compare 3 files as sample output: $ diff3 parent.txt your.txt mine.txt ==== 1:1,2c Hello, This is parent file. 2:1,2c Hello, This is your file. 3:1,2c Hello, This is my file. You can use diff3 file1.txt file2.txt file3.txt > output.txt


0

I wrote this answer before noticing that you want to use the column command, but if that isn’t a requirement, you can center text with this bash shell script: #!/bin/bash set -e # exit the script if something goes wrong width=12 data="temperatures 50 12 89 63" for word in $data; do strlen=$(printf $word | wc -c) w=$(( ($width - $strlen)/2 )) ...



Top 50 recent answers are included