New answers tagged

0

Here is the command for matching records - awk -F, 'FNR==NR{f1[$1]=$0;next}$2 in f1{print $0}' OFS="," file1 file2 > matchedRecords.txt


3

Pure bash solution while IFS=\, read -r a b ; do echo "$a;$b" ; done <file.csv Or just for fun paste -d\; <(cut -d, -f1 file.csv) <(cut -d, -f1 --complement file.csv)


11

The g in: sed 's/,/;/g' is for globally, that is to substitute all occurrences of , with ;. If you want to do only one substitution per line, take off the g: sed 's/,/;/' And for completeness: You can also specify which occurrence to substitute. For instance, to substitute only the second occurrence: sed 's/,/;/2' With GNU sed, you can also ...


0

Following on from Peter.O's comment which is what I wanted to align (tab delimited data, TSV), this phrase works very nicely: column -t -s $'\t' /Users/me/data.csv | less --chop-long-lines


1

I know this question's been answered, I figured I'd just add my two cents as to how to accomplish this in a (ugly) bash one-liner End Result echo -e $(cut -d"=" -f1 OpenSimStats.txt | tr '\n' ',' | sed 's/,$/\\n/')$(sed -r 's/.*=([0-9]*).*/\1,/g' OpenSimStats.txt | tr -d '\n' | sed 's/,$//') This will produce the following result you asked for in one ...


2

The following gawk program should work for you: echo -e "unixtime;host_name;ip_adress;description;2;0;1\n1234567890;hName;hIP;hDesc;2;1;0" | gawk -F";" 'BEGIN {OFS=";"} { if (NR<2) next; $1=strftime("%Y-%m-%d %H:%M:%S", $1); $5=($5==2?"CRITICAL":$5); $6=($6?"Yes":"No") ; $7=($7?"Yes":"No") ; print}' 2009-02-14 00:31:30;hName;hIP;hDesc;CRITICAL;...


3

Here's a Perl solution: $ perl -F= -lae '$F[1]=~s/[^0-9]//g; push @h,$F[0]; push @l,$F[1]; END{print join ",",@h; print join ",",@l}' OpenSimStats.txt TestreportsRootAgentCount,TestreportsChildAgentCount,TestreportsGCReportedMemory,TestreportsTotalObjectsCount,TestreportsTotalPhysicsFrameTime,TestreportsPhysicsUpdateFrameTime,...


9

The 9 paths to OpenSim enlightenment: With sed and some shell magic: sed 's/=.*//' OpenSimStats.txt | paste -sd, >out.csv sed 's/.*=//; s/[^0-9]*$//' OpenSimStats.txt | paste -sd, >>out.csv With sed, without shell magic: sed -n 's/=.*//; 1{ h; b; }; $! H; $ { x; s/\n/,/g; p; }' OpenSimStats.txt >out.csv sed -n 's/.*=//; 1{ s/[0-9]*$//; h; b; ...


8

awk to help you: awk -F= '{a[NR,1]=$1;a[NR,2]=$2} END{ for(i=1; i<NR; i++){ printf a[i,1] "," } print a[i,1]; for(i=1; i<NR; i++){ printf "%s", a[i,2]+0 } print a[i,2]; }' file The array a is filled with both key $1 in the first ...


1

While you can do mysql queries/updates/etc in a shell script, it's far easier to use a language (like perl or python) with good support for both databases and CSV files. Here's one way of doing it in perl, using the perl DBI module, and the DBD::CSV and DBD::mysql modules. It reads each row from your CSV file (i've called it 'updates.csv' and assumed the ...


0

You can use this script: #!/bin/bash PREFIX="A2B1 " TABLE="sqltablename" COLUMN="sqlcolumnname" if [[ ! -r "$1" ]]; then echo "unable to read file '$1'" exit 1 fi cut -d, -f2 "$1" | while read phonenum; do newnum="$PREFIX $phonenum" echo "UPDATE $TABLE SET $COLUMN = '$newnum' WHERE $COLUMN = '$phonenum';" done This will, if you run it with ...


0

Use lxprintf from the ltXML2 toolkit (Edinburgh University), eg: $ lxprintf -e data "%s;%s;%s\n" ../id_localisation id_client key test.xml 8PJ;50C;C 8PJ;25C;D1 ESP31;70D;D2 ESP31;10D;D3 Using XSLT2 is fine, but overkill for this kind of extracting. XML FAQ: http://xml.silmaril.ie/


1

A little ruby one-liner ruby -rcsv -ne ' row = CSV.parse_line($_) if $. == 1 then keys = row else h = Hash[keys.zip(row)] puts h.to_s + "," end ' outputs {"sortorder"=>"1", "name"=>"B.1", "description"=>"Boiler room"}, {"sortorder"=>"2", "name"=>"1.1", "description"=>"First office"}, {"sortorder"=&...


1

General sed solution (without fields resorting) sed ' 1{ h d } G :a s/\(^\|,\)\([^=]\+\n\)"\?\([^,]\+\)"\?,\?/\1 \3 => \2/ ta s/^/{/ s/\n/ },/ ' file.csv But if you'd like a fist field become the last - just add s/\([^,]*\), \([^\n]*\)/\2, \1/ after ta


0

Using perl script #!/usr/bin/perl open INFILE, "<", "inputfile"; open OUTFILE, ">", "outputfile"; $header_line = <INFILE>; chop($header_line); @headers = split /,/, $header_line; foreach $header_column (@headers) { $header_column =~ s/^"(.*)"$/$1/; } while(<INFILE>) { chop($_); # clear the newline at the end of string @...


2

Here's a perl script that reads in each line of each file specified on the command line and appends it to elements in the array (@csv). When there's no more input, it prints out each element of @csv. The .csv files will be appended in the order that they are listed on the command line. WARNING: This script assumes that all input files have the same number ...


1

The simplest approach for achieving that would be typing the following command cat *csv > combined.csv This file would contain the contents of all your csv files just in the way you mentioned.



Top 50 recent answers are included