Sequence in one single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sequence in one single line
# 8  
Old 06-19-2010
Quote:
Originally Posted by danmero
What about this one ?
Code:
awk '{printf (/^>/)?((NR==1)?x:RS)$0 RS:$0}' file


Yep, nice!

However using printf without the format specifier could be dangerous. If the input contains special (for printf) characters the code could fail:


Code:
% print %d | awk '{ printf $0 }'
awk: (FILENAME=- FNR=1) fatal: not enough arguments to satisfy format string
        `%d'
          ^ ran out for this one

So, it would be a bit safer to add the format specifier (I also added the final newline):

Code:
awk 'END { print x }
  { 
    printf "%s", /^>/ ? (NR == 1 ? x : RS) $0 RS : $0
     }' infile

P.S. If I recall correctly some awk implementations (nawk on Solaris?) would require more parens., just like in your post.

Last edited by radoulov; 06-19-2010 at 06:16 AM..
# 9  
Old 06-19-2010
Quote:
Originally Posted by radoulov
However using printf without the format specifier could be dangerous. If the input contains special (for printf) characters the code could fail:
You are correct (as always), I just drop this "short" oneliner at 3:21 AM Smilie
# 10  
Old 06-19-2010
Hi


Code:
sed -e :a -e '/^>/!N;s/\n[^>]/ /;ta' file

Guru.
# 11  
Old 06-19-2010
Quote:
Originally Posted by guruprasadpr
Hi


Code:
sed -e :a -e '/^>/!N;s/\n[^>]/ /;ta' file

Guru.
Very nice Smilie

P.S. It seems that the OP asks for:

Code:
s/\n[^>]//



---------- Post updated at 11:52 AM ---------- Previous update was at 11:48 AM ----------

Quote:
Originally Posted by danmero
[...]I just drop this "short" oneliner at 3:21 AM Smilie
Yes, it's not fair Smilie
It's 11.51 AM here Smilie
This User Gave Thanks to radoulov For This Post:
# 12  
Old 06-19-2010
Quote:
Originally Posted by radoulov
Yes, it's not fair Smilie
It's 11.51 AM here Smilie
Yep, I know..

Quote:
Originally Posted by radoulov
Very nice Smilie

P.S. It seems that the OP asks for:
Maybe we should run a diff for each output. My is missing the last new line only.
guruprasadpr solution look nice but no go.
# 13  
Old 06-19-2010
Quote:
Originally Posted by danmero
[...]
Maybe we should run a diff for each output. My is missing the last new line only.
guruprasadpr solution look nice but no go.
Yep,
I overlooked that, the sed solution gives a different result.
# 14  
Old 06-19-2010
@Radoulov

The 'sed' solution gives the result as expected in the 'output' attachment. What is it missing?

Guru.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print Line as per the dependent sequence in shell script.

Hi i have a file like this as shown below: DA PROCESS_ID IDENTIFIER DA_FILE STATUS WAITING_FOR SCOPED_DEPENDENT 1836 21000 01052019 BH90P.TEMP.DA1836.FTP W NULL ... (6 Replies)
Discussion started by: krishnaswarnkar
6 Replies

2. Shell Programming and Scripting

Creating a sequence of numbers in a line for 1000 files

Hi, I try to explain my problem , I have a file like this: aasdsaffsc23 scdsfsddvf46567 mionome0001.pdb asdsdvcxvds dsfdvcvc2324w What I need to do is to create 1000 files in which myname line listing a sequence of numbers from 0001 to 1000. So I want to have : nomefile0001.txt that must... (10 Replies)
Discussion started by: danyz84
10 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

5. Shell Programming and Scripting

How to get line after occurence of sequence of patterns

In the past I needed a help with the problem how to search for pattern after the occurence of another pattern which is described in this thread: https://www.unix.com/shell-programmin...-pattern1.html Now I would need something quite similar, only the pattern which is to be searched must be... (3 Replies)
Discussion started by: sameucho
3 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

filter out a sequence from multiple lines line

Hi, I have an unwanted string at random lines of my verilog (*.v) file. (* abccddee *) input A; (* xyz *) input B; (* 1234 *) output C; I want a clean file like this: input A; input B; output C; the unwanted string begins with "(*" and ends with "*)" at multiple lines. Any help... (2 Replies)
Discussion started by: return_user
2 Replies

8. Shell Programming and Scripting

printing sequence of line no. with comma separated

Kindly i want to concatenate every 12 lines ina file, using a comma separator between fields (each line)? can anyone help please? thanks a lot in advance. (5 Replies)
Discussion started by: m_wassal
5 Replies

9. UNIX for Dummies Questions & Answers

Executing a sequence of commands as a single background process

I'm writing a PHP script which will take a given media file and convert it into a flash (flv) file. In addition to this, once the flv file has been generated I create two thumbnails (of different sizes) from the newly generated flv file. In order to do this I'm calling ffmpeg from the command... (4 Replies)
Discussion started by: phatphug
4 Replies

10. Shell Programming and Scripting

Reorder the sequence of line groupings/QIF export

Hi All, I need to reorder the sequence of line groupings - specifically the output from a bank QIF (Quicken Interchange Format) export. Sample is like this: !Type:Bank D12/05/2008 T-10.00 N1 Details of Charge 1 ^ D07/05/2008 T-20.00 N2 Details of Charge 2 ^ D17/04/2008 T-30.00 (0 Replies)
Discussion started by: mark101
0 Replies
Login or Register to Ask a Question