New answers tagged

2

Just a quick point; awk is a lot more flexible, but if all you want is a particular range of fields, use cut: cut -d, -f1-5 huge_log_file.csv This is much simpler than an awk loop if that's all you need.


2

Ranges that begin with the first field Let's consider this test file: $ cat input.csv a,b,c,d,e,f,g,h,i,j With GNU awk at least, we can print the first five (or other number) of fields like this: $ awk -F, '{NF=5; print}' OFS=, input.csv a,b,c,d,e For those who value conciseness over clarity, we could equivalently write: $ awk -F, '{NF=5;} 1' OFS=, ...


0

#! /usr/bin/perl use strict; use warnings; my %files=(); my @files=(); my $currentfile=''; my $maxcols=1; while(<>) { chomp; # a hash such as %files is inherently unordered, so store each # filename we process in @files, in the order that we see them. if ($currentfile ne $ARGV) { $currentfile = $ARGV ; push @files, $currentfile; }; ...


1

just a wild guess awk 'BEGINFILE { printf "%s",FILENAME} { printf ",%s",$0 ;} ENDFILE { printf "\n" ;}' file1.txt file2.txt file3.txt this will turn file to csv (but unquoted), file being converted to one line. replace ",%s" by "\t%s" to use tab.


0

First combine all the text files: cat Article1.txt Article2.txt Article3.txt > Result.txt Then convert the text file to CSV: (echo "Col1;Col2;Col3" ; cat Result.txt) | sed 's/;/<tab>/g' > file.csv



Top 50 recent answers are included