Tag Info

New answers tagged

0

One way to add a header line to an existing file is to use sed. The -i option causes sed to upddate the input file. The 1 means: when processing line number 1. The i command will insert a line of text. sed -i '1i Name,Type,Output,XYZ,ABC' csv_comparison_file Assuming that your original CSV comparison results file contains: foo,bar,baz,yabba,dabba ...


1

In addition to Gabriele Lana's answer please note that BSD paste command needs dash to be specified to read content from standard input. manual of paste command If '-' is specified for one or more of the input files, the standard input is used; standard input is read one line at a time, circularly, for each instance of '-'. So final need to ...


13

cut -d / -f 4 file1.txt | paste -sd '|' | xargs -I{} grep -v -E {} file2.csv Explanation: cut -d / -f 4 file1.txt will select the hashes from the first file paste -sd '|' will join all the hashes into a regular expression ex. H1|H2|H3 xargs -I{} grep -v -E {} file2.csv will invoke grep with the previous pattern as an argument, xargs will replace {} with ...


0

sed '/,65[0-9]*,Real Estate/! d' file.txt


5

For GNU sed sed -z 's%.*/\([^/]*\)/index.html\n%\1\\|%g;s%^%/%;s%\\|$%/d%' file1.csv | sed -f - file2.csv where first sed produce list of hashes in sed-command-format like /12ab09f46\|a77b3ff22\|..../d and transfer it to next sed-script which reads above command from input therefore -f - option. Same with grep grep -oP '[^/]*(?=/index.html$)' file1.csv | ...


2

with awk awk -F, '{if ( $11 ~ /^65/ ) print $0}' file explanation: use comma as field separator -F, , check if column 11 starts (^) with 65 if ( $11 ~ /^65/ ), if so print whole line print $0


1

This should do it: #!/usr/bin/env perl use strict; use warnings; while ( <> ) { print if (split /,/)[10] =~ m/^65/; } Can one liner it if you like as: perl -ne 'print if (split /,/)[10] =~ m/^65/;' yourfile


2

I've just tried the following one liner, and it seems to do the job: for i in `cat file1.txt | awk -F"/" '{print $4}'`; do echo "\n $i" ; sed -ri "/^$i,/d" file2.csv ; done Please replace first -ri with -re to test it. -re does a dry run, and if all is ok you can run it with -ri


2

#!/bin/bash cut -d, -f1 file2 | while read key ; do #check for appearance in file1 with successful grep: #exit status is 0 if pattern is found, only search for at least 1 #appearance -> to speed it up if [[ $(grep -m 1 "/$key/" file1) ]] ; then sed "/^$key,/d" -i file2 #note that we are gradually overwriting file2 (-i option), ...


11

Possible awk solution: awk 'NR == FNR { x[$4] = 1; next; } { if (!($1 in x)) print $0; }' FS="/" file1.txt FS="," file2.txt First we read file1.txt using FS (field separator) "/" and create array x with keys values from field $4 which is the hash you want. Next we read second file file2.txt setting FS to be , and check if value of field $1 does not exist ...


3

libreoffice offers this option, I cannot tell about resource use, though: libreoffice --headless --convert-to csv $filename(s) --outdir $outdir --outdir is optional and will be the current working dir if not specified, batch mode is possible by simply specifying multiple files.


2

Fedora/Redhat/CentOS: yum install gnumeric Debian/Ubuntu: apt-get install gnumeric ssconvert myexcel.xlsx myexcel.csv Reference: Gnumeric man ssconvert


1

A method to skip importing would be to convert the file to a format that can be read without importing - so for instance: soffice --headless --convert-to ods --outdir /tmp tblIssues.csv soffice --view /tmp/tblIssues.ods rm /tmp/tblIssues.ods This converts the file tblIssues.csv to a ODS spreadsheet, saves it to /tmp and opens it in Libreoffice. Once it ...


1

Install unoconv (just once) On Ubuntu run sudo apt-get install unoconv On RHL/CentOS run sudo yum install unoconv To convert on command-line or batch-mode (non-interactively) unoconv -f pdf /pathto/file.csv /pathto/file.pdf 2>/dev/null THAT'S IT! Notes: I pipe standard error to /dev/null because I get an error that 'looks' like the conversion ...


1

Please, on behalf of future maintenance programmers and sysadmins - DON'T use a regex to parse XML. XML is a structured data type, and it is NOT well suited for regex parsing - you can 'fake it' by pretending it's plain text, but there's a bunch of semantically identical things in XML that don't parse the same. You can embed linefeeds, and have unary tags ...


0

As per information on rpm.pbone.net xls2csv-1.06-14.fc19.noarch.rpm package provides: Content of RPM : /usr/bin/convertxls2csv /usr/share/man/man1/convertxls2csv.1.gz So you can use convertxls2csv instead of xlsx2csv command from this package. I think it works same as you wanted. For more information see man page: man convertxls2csv.


0

if both field are in 8th column among 24 paste originalfile1 originalfile2 | awk '{print $8+$32 ; }' > file3


0

for avoiding an intermediate file, use: paste <( awk -F, '{ print $8 }' original_file1 ) <( awk -F, '{ print $8 }' original_file2 ) | awk '{print $1+$2}' > file3


3

paste File1 File2 | awk '{ print $1 + $2; }' > File3



Top 50 recent answers are included