Concatenate two columns of a text file


Stanton Arch

I have a tsv file like

1   2   3   4   5   ...
a   b   c   d   e   ...
x   y   z   j   k   ...

How can I merge two consecutive columns, say second and third, to get

1   2-3   4   5   ...
a   b-c   d   e   ...
x   y-z   j   k   ...

I need code to handle text files with different numbers of columns, so can't use something likeawk 'BEGIN{FS="\t"} {print $1"\t"$2"-"$3"\t"$4"\t"$5}' file

awkis the first tool that comes to my mind and is the one I'm trying to learn, so I'm very interested in answers using it, but solutions using any other tools would be greatly appreciated.

Roman Pellechrest

Use a simple tsv file command :sed

sed 's/\t/-/2' file

output:

1   2-3 4   5   ...
a   b-c d   e   ...
x   y-z j   k   ...

Related


How to concatenate two columns in a csv file in php?

Patrick 62 I have a csv file like this: I want to concatenate the values of the style_color column in this csv file. For example with SCJEG4_1014. I wrote a script that creates the last column with the header "Pictures Names", but in each cell I only have "_".

Concatenate column text headers if two columns total equal

Wolf I have three columns, each heading let's call it: column , column B, column c . There are 10 questions per column, total at the end. If the totals of the 2 columns are equal, join the column headers together and insert an "or" in between. That is, if colu

Concatenate two text columns in dplyr

mmyoung77 My data looks like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 9.782025 2

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

How to concatenate two columns in a csv file in php?

Patrick 62 I have a csv file like this: I want to concatenate the values of the style_color column in this csv file. For example with SCJEG4_1014. I wrote a script that creates the last column with the header "Pictures Names", but in each cell I only have "_".

Concatenate two separate text columns for each ID

plunder I know it is possible to concatenate a line using the following code. For example, make one line of StudentName text for each discipline ID. sample data Patient_FIN StudentName ---------- ------------- 1 Mary 1

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

Concatenate two text columns in dplyr

mmyoung77 My data looks like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 9.782025 2

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

Concatenate two separate text columns for each ID

plunder I know it is possible to concatenate a line using the following code. For example, make one line of StudentName text for each discipline ID. sample data Patient_FIN StudentName ---------- ------------- 1 Mary 1

Concatenate two columns of text alphabetically in Excel

Jasmine B I am using this airport data spreadsheet. Sorry, can't figure out how to format the headers, but the first column is Origin IATA, the second is Dest IATA, and the third is Concatenate Route Origin IATA, Dest IATA, Concatenate Route LHR

Concatenate text to columns in Pig

Michal I have a column for day and month and want to concatenate the years and store CHARARRAYin hyphenated format . So I have:month:CHARARRAY, day:CHARARRAY For example, if the "Date" column contains "03" and the "Month" column contains "04", I want to create

concatenate two columns in python

sorin beginner Reunion, I want to concatenate two columns in one csv file and put this string into another csv file but into a single column. Code I have tried: import csv file1=open('Source.csv','r') readfile=csv.reader(file1,delimiter=';') file2=open('Outp

How to concatenate two columns

user 2009265 I need to concatenate two columns firstnameand lastnameselect names in a crosstab like: select * from crosstab('SELECT concat(u.firstname," ",u.lastname)as name But I get this error: column « » doesn't exist. what should I do? Robert N Try this

Concatenate column text headers if two columns total equal

Wolf I have three columns, each heading let's call it: column , column B, column c . There are 10 questions per column, total at the end. If the totals of the 2 columns are equal, join the column headers together and insert an "or" in between. That is, if colu

Concatenate text to columns in Pig

Michal I have a column for day and month and want to concatenate the years and store them in CHARARRAYa hyphenated format . So I have:month:CHARARRAY, day:CHARARRAY For example, if the "Date" column contains "03" and the "Month" column contains "04", I want to

How to concatenate two columns in a csv file in php?

Patrick 62 I have a csv file like this: I want to concatenate the values of the style_color column in this csv file. For example with SCJEG4_1014. I wrote a script that creates the last column with the header "Pictures Names", but in each cell I only have "_".

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

Concatenate two text columns in dplyr

mmyoung77 My data looks like this: round <- c(rep("A", 3), rep("B", 3)) experiment <- rep(c("V1", "V2", "V3"), 2) results <- rnorm(mean = 10, n = 6) df <- data.frame(round, experiment, results) > df round experiment results 1 A V1 9.782025 2

Concatenate two strings to text file in Powershell

afaque.khan1 I am trying to join two strings in Powershell and export to a file, but I am not getting the desired result, I am very new to Powershell. $vm=Get-Content "c:\vmfile.txt" ForEach($vm1 in $vm) { $boot="_boot.vhd" $bname=$vm1+$boot write-output

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

Concatenate two columns of a text file

Stanton Arch I have a tsv file like 1 2 3 4 5 ... a b c d e ... x y z j k ... How can I merge two consecutive columns, say second and third, to get 1 2-3 4 5 ... a b-c d e ... x y-z j k ... I need code to

concatenate two columns in python

sorin beginner Reunion, I want to concatenate two columns in one csv file and put this string into another csv file but into a single column. Code I have tried: import csv file1=open('Source.csv','r') readfile=csv.reader(file1,delimiter=';') file2=open('Outp

Concatenate text to columns in Pig

Michal I have a column for day and month and want to concatenate the years and store them in CHARARRAYa hyphenated format . So I have:month:CHARARRAY, day:CHARARRAY For example, if the "Date" column contains "03" and the "Month" column contains "04", I want to