Combine rows with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine rows with awk
# 1  
Old 06-29-2015
Combine rows with awk

I have a file of 100,000 entries that look like:

Code:
chr1	980547	980667	+
	chr1:980547-980667
chr1	980728	980848	+
	chr1:980728-980848
chr1	980793	980913	+
	chr1:980793-980913

I am trying to reformat them to into 5 columns that are tab delineated:

Code:
chr1	980547	980667	+     chr1:980547-980667
chr1	980728	980848	+     chr1:980728-980848
chr1	980793	980913	+     chr1:980793-980913

Maybe:
Code:
 awk 'NR%2{printf $0" ";next;}1 "/t"' file

Sorry scientist trying to learn, thank you Smilie.
# 2  
Old 06-29-2015
Close

Code:
awk 'NR%2{printf $0" ";next;}1' file

This User Gave Thanks to senhia83 For This Post:
# 3  
Old 06-29-2015
Thank you Smilie.
# 4  
Old 06-29-2015
With sed
Code:
sed 'N;s/\n//' file

Here it's simple to delete the + character:
Code:
sed 'N;s/+\n//' file

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Combine awk scripts

Hi, Below command is working as expected, but would like to know how to club the two AWK scripts in the command into one echo -e "MMS000101S0203430A|20180412E|\nMMB0001INVESTMENT||107-86193-01-03|\nMMB0001FUND||107-86193-04-01|\nMMC9991 " | awk -F'|' -v OFS=, '/^MMC9991/{print r"|"s,t; next}... (3 Replies)
Discussion started by: JSKOBS
3 Replies

2. Shell Programming and Scripting

Combine two awk commands

Hi, Can someone please guide me how to combine the following two awk calls in one? I noticed that it is very often situation for me, and I think that it can be replaced with one awk call. The question is more general, not the exact one. echo "A B C/D" | awk '{print $3}' | awk -F/ '{print... (4 Replies)
Discussion started by: mirusnet
4 Replies

3. Shell Programming and Scripting

Combine multiple rows based on selected column keys

Hello I want to collapse a file with multiple rows into consolidated lines of entries based on selected columns as the 'key'. Example: 1 2 3 Abc def ghi 1 2 3 jkl mno p qrts 6 9 0 mno def Abc 7 8 4 Abc mno mno abc 7 8 9 mno mno abc 7 8 9 mno j k So if columns 1, 2 and 3 are... (6 Replies)
Discussion started by: linuxlearner123
6 Replies

4. Shell Programming and Scripting

How to find DISTINCT rows and combine in one row?

Hi , i need to display only one of duplicated values and merged them in one record only when tag started with 3100.2.128.8 3100.2.97.1=192.168.0.12 3100.2.128.8=418/66/03e9/0044801 3100.2.128.8=418/66/03ea/0044601 3100.2.128.8=418/66/03e9/0044801 3100.2.128.8=418/66/03ea/0044601... (5 Replies)
Discussion started by: OTNA
5 Replies

5. Shell Programming and Scripting

Combine rows from two files

I have two files, called "File A" and "File B". File A hdisk120: iprod_0000151 dprod_0000135 iprod_0000148 dprod_0000148 iprod_0000157 iprod_0000155 hdisk118: dprod_0000141 dprod_0000134 dprod_0000155 iprod_0000166 dprod_0000129 lprod_0000017 iprod_0000146 (5 Replies)
Discussion started by: Daniel Gate
5 Replies

6. Shell Programming and Scripting

How to combine two files with awk?

Hi, everyone! I have two files, I want to combine them as follows: File1 AAAA 23 45 AAAB 44 56 AAAC 34 65 AAAD 34 87 File2 AAAA 34 54 AAAE 34 56 Combined file AAAA 23 45 34 54 AAAB 44 56 AAAC 34 65 AAAD 34 87 AAAE 34 56 (13 Replies)
Discussion started by: xshang
13 Replies

7. Shell Programming and Scripting

Combine 2 files by rows

Hi, I have 2 files, each files contain about 1 millions lines and I want to joint them to build the new files which contain each 2 lines of file1 and 1 lines of file2. Newfiles: line1-file1 line2-file1 line1-file2 line3-file1 line4-file1 line2-file2 ..... Could someone help... (8 Replies)
Discussion started by: thinhnguyenfr
8 Replies

8. Shell Programming and Scripting

combine awk and tr -d

Hi Everyone, awk 'BEGIN{print strftime("%c",1272814948)}' | tr -d '\n' how to change tr -d '\n' to be part of the awk? means awk this pchoh time, and awk also remove '\n', instead of using "|" to combine "tr" command. Thanks (2 Replies)
Discussion started by: jimmy_y
2 Replies

9. Shell Programming and Scripting

Combine awk statements

I have an awk statement that works but I am calling awk twice and I know there has to be a way to combine the two statements into one. The purpose is to pull out just the ip address from loopback1. cat config.txt | nawk 'BEGIN {FS="\n"}{RS="!"}{if ( $0 ~ "interface loopback1" ) print$4}' | nawk... (5 Replies)
Discussion started by: numele
5 Replies

10. Shell Programming and Scripting

awk : combine 3 variables into 1

Within one of my awk scripts, I have three variables extracted and calculated on. When done, I simply want to combine the three. The following works, but looks weird. My script reads a field that has text and numbers, knowing the last four comprise MMYY (month and year) # YY are last two... (2 Replies)
Discussion started by: joeyg
2 Replies
Login or Register to Ask a Question