Python Forum
code wanted: file splicing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
code wanted: file splicing
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
You can try cut
or awk
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Mar-24-2018, 07:38 AM)wavic Wrote: You can try cut
or awk
so how to combine the multiple files into one?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
cat file1 file2 file3 file4 > final_file
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
He wants to get specific columns from each file and make a new file from them.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
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.
Reply
#8
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#9
10 years. Dodgy
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#10
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  wanted: regex or code to find valide def statements in a line Skaperen 13 5,640 Mar-20-2020, 11:54 PM
Last Post: Skaperen
  python code wanted: grep IP address Skaperen 7 6,189 Jul-09-2018, 05:25 AM
Last Post: Skaperen
  code wanted, but don't expect me to do it Skaperen 0 2,110 Jul-07-2018, 10:50 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020