Python Forum

Full Version: code wanted: file splicing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
i often need a command to take particular columns of different files and combine them. for example i just needed to take columns 1-19 of file A and columns 20-EOL of file B and output it. line 37 would come from line 37 of both files.
You can try cut
or awk
(Mar-24-2018, 07:38 AM)wavic Wrote: [ -> ]You can try cut
or awk
so how to combine the multiple files into one?
Hm! This will require some bash scripting and I am not aware of it. I think Pandas python module can do this.
I can try later to do some bash magic. It's embarrassing that I am using Linux for years and still don't know the bash scripting syntax.
cat file1 file2 file3 file4 > final_file
He wants to get specific columns from each file and make a new file from them.
What's a "column"?

Are these csv files? Or is each character a different column? If it's each character, what about multi-byte characters?

Without example input/output, the likelihood of finding preexisting code is minimal.
(Mar-26-2018, 10:48 AM)DeaD_EyE Wrote: [ -> ]
cat file1 file2 file3 file4 > final_file

and while cutting specified columns in each?

(Mar-26-2018, 08:23 AM)wavic Wrote: [ -> ]Hm! This will require some bash scripting and I am not aware of it. I think Pandas python module can do this.
I can try later to do some bash magic. It's embarrassing that I am using Linux for years and still don't know the bash scripting syntax.
i'd rather do new things in Python.

when did you start using Linux? i started in 1993. but i was using muliple Unix before then, and some even since then, so i had a head start.

(Mar-26-2018, 03:23 PM)nilamo Wrote: [ -> ]What's a "column"?

Are these csv files? Or is each character a different column? If it's each character, what about multi-byte characters?

Without example input/output, the likelihood of finding preexisting code is minimal.

some might be CSV files. i'm working on a design for a new command.
10 years. Dodgy
https://www.joeldare.com/wiki/using_awk_on_csv_files

awk -F "," '{OFS=","; print $2,$9}' ./Dropbox/opc_client/ULD\ Numbers\ optimized\ for\ PLC\ -\ ULD\ Numbers.csv
OFS = Output Field Separator

Output:
A Certified Aircraft Container,AAA 46201 LH A Certified Aircraft Container,AAD 46202 AF A Certified Aircraft Container,AAF 46203 KL A Certified Aircraft Container,AAP 46204 LH ...
awk -F "," '{OFS=","; print $2,$9}' ./Dropbox/opc_client/ULD\ Numbers\ optimized\ for\ PLC\ -\ ULD\ Numbers.csv > result1.csv
Then you can do the same with the other files.
Then you concatenate the files afterwards.
Pages: 1 2