Output on one line using awk or sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output on one line using awk or sed
# 1  
Old 07-22-2015
Output on one line using awk or sed

I have a file of 100,000 lines in the below format:

answer.bed
Code:
chr1    957570    957852    
     NOC2L
chr1    976034    976270     
     PERM1
chr1    976542    976787    
     PERM1

I need to get each on one line and so far what I have tried doesn't seem to be working. Thank you Smilie.

Desired output:

Code:
chr1    957570    957852     NOC2L
chr1    976034    976270     PERM1
chr1    976542    976787     PERM1

I have tried:
Code:
 sed 'N;s/\n//' answer.bed > output.bed

output.txt
Code:
chr1    957570    957852     NOC2Lchr1    976034    976270     PERM1
chr1    976542    976787     PERM1chr1    978907    979122     PERM1
chr1    979192    979413     PERM1chr1    979478    979647     PERM1


Code:
 awk 'NR%2{printf $0" ";next;}1' answer.bed > output.bed

output.txt
Code:
chr1    957570    957852     NOC2L chr1    976034    976270     PERM1
chr1    976542    976787     PERM1 chr1    978907    979122     PERM1
chr1    979192    979413     PERM1 chr1    979478    979647     PERM1

# 2  
Old 07-22-2015
I can't reproduce your problem; both code snippets work as expected. You had problems originating from using DOS/<CR> terminators before; could that be a possible reason?
These 2 Users Gave Thanks to RudiC For This Post:
# 3  
Old 07-22-2015
Code:
xargs -n4 <answer.bed >output.bed

Code:
# cat /tmp/myt
chr1    957570    957852
     NOC2L
chr1    976034    976270
     PERM1
chr1    976542    976787
     PERM1
# xargs -n4 </tmp/myt
chr1 957570 957852 NOC2L
chr1 976034 976270 PERM1
chr1 976542 976787 PERM1
#

This User Gave Thanks to ctsgnb For This Post:
# 4  
Old 07-22-2015
I will remove the DOS/<CR> terminators before;, that is it as the original file was from excel. Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

3. Shell Programming and Scripting

Problem with output awk and sed

I have file, i am extracting email address from file. but problem is that output is very ugly. I am using this command REMOVED "CSS OFFENDING CODE"... While original filename have no such character. Please suggest. (20 Replies)
Discussion started by: learnbash
20 Replies

4. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

5. Shell Programming and Scripting

Insert output from a file to beginning of line with sed

Hi I've been trying to search but couldn't quite get the answer I was looking for. I have a a file that's like this Time, 9/1/12 0:00, 1033 0:10, 1044 ... 23:50, 1050 How do I make it so the file will be like this? 9/1/12, 0:00, 1033 9/1/12, 0:10, 1044 ... 9/1/12, 23:50, 1050 I... (4 Replies)
Discussion started by: diesel88
4 Replies

6. Shell Programming and Scripting

sed and Output line too long

hello i try this command in console mode sed -e :a -e '/$/N; s/\(\)\n/\1 /; ta' test.txt > result.txt i have in the output screen "Output line too long" for multiples lines can you please tell me how can i retrieve those long lines during the execution ? Another thing very... (5 Replies)
Discussion started by: ade05fr
5 Replies

7. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

8. Shell Programming and Scripting

single line input to multiple line output with sed

hey gents, I'm working on something that will use snmpwalk to query the devices on my network and retreive the device name, device IP, device model and device serial. I'm using Nmap for the enumeration and sed to clean up the results for use by snmpwalk. Once i get all the data organized I'm... (8 Replies)
Discussion started by: mitch
8 Replies

9. UNIX for Dummies Questions & Answers

sed output without a new line

I am reading file and extracting the paragraph between START and END tags. contents of abc.txt Remember that $ means the last line in a file. You can also specify a range based on two regexps. Try START Note that this prints all blocks starting with lines containing regexp1 through lines... (1 Reply)
Discussion started by: ganesh_mak
1 Replies

10. Shell Programming and Scripting

Read logline line by line with awk/sed

Hello, I have a logfile which is in this format: 1211667249500#3265 1211667266687#2875 1211667270781#1828 Is there a way to read the logfile line by line every time I execute the code and put the two numbers in the line in two separate variables? Something like: 1211667249500#3265... (7 Replies)
Discussion started by: dejavu88
7 Replies
Login or Register to Ask a Question