Create specific output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create specific output
# 1  
Old 07-02-2015
Create specific output

I have a file that looks like the below and only need certain lines, but am not sure how to do that. It is basically everything from the @HD up to the @RG. Thank you Smilie.

file.txt - input
Code:
@HD    VN:1.4    GO:none    SO:coordinate @SQ    SN:chr1    LN:249250621 @SQ    SN:chr2    LN:243199373 @SQ    SN:chr3    LN:198022430 @SQ    SN:chr4    LN:191154276 @SQ    SN:chr5    LN:180915260 @SQ    SN:chr6    LN:171115067 @SQ    SN:chr7    LN:159138663 @SQ    SN:chr8    LN:146364022 @SQ    SN:chr9    LN:141213431 @SQ    SN:chr10    LN:135534747 @SQ    SN:chr11    LN:135006516 @SQ    SN:chr12    LN:133851895 @SQ    SN:chr13    LN:115169878 @SQ    SN:chr14    LN:107349540 @SQ    SN:chr15    LN:102531392 @SQ    SN:chr16    LN:90354753 @SQ    SN:chr17    LN:81195210 @SQ    SN:chr18    LN:78077248 @SQ    SN:chr19    LN:59128983 @SQ    SN:chr20    LN:63025520 @SQ    SN:chr21    LN:48129895 @SQ    SN:chr22    LN:51304566 @SQ    SN:chrX    LN:155270560 @SQ    SN:chrY    LN:59373566 @SQ    SN:chrM    LN:16569 @RG    ID:8AH6U.IonXpress_009    PL:IONTORRENT    PU:Unspecified/P1.1.17/IonXpress_009    FO:TACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACGTCTGAGCATCGATCGATGTACAGCTACGTACG    DT:2015-06-03T14:03:02-0700    SM:E1    PG:tmap    KS:TCAGTGAGCGGAACGAT    CN:TorrentServer/Proton

Desired output
Code:
@HD    VN:1.4    GO:none    SO:coordinate @SQ    SN:chr1    LN:249250621 @SQ    SN:chr2    LN:243199373 @SQ    SN:chr3    LN:198022430 @SQ    SN:chr4    LN:191154276 @SQ    SN:chr5    LN:180915260 @SQ    SN:chr6    LN:171115067 @SQ    SN:chr7    LN:159138663 @SQ    SN:chr8    LN:146364022 @SQ    SN:chr9    LN:141213431 @SQ    SN:chr10    LN:135534747 @SQ    SN:chr11    LN:135006516 @SQ    SN:chr12    LN:133851895 @SQ    SN:chr13    LN:115169878 @SQ    SN:chr14    LN:107349540 @SQ    SN:chr15    LN:102531392 @SQ    SN:chr16    LN:90354753 @SQ    SN:chr17    LN:81195210 @SQ    SN:chr18    LN:78077248 @SQ    SN:chr19    LN:59128983 @SQ    SN:chr20    LN:63025520 @SQ    SN:chr21    LN:48129895 @SQ    SN:chr22    LN:51304566 @SQ    SN:chrX    LN:155270560 @SQ    SN:chrY    LN:59373566 @SQ    SN:chrM    LN:16569

# 2  
Old 07-02-2015
What do you mean "I have a file that looks like the below and only need certain lines"? You have shown us same input that is a single line. And the output you want is also a single (although shorter) line.

Are you saying that some lines don't contain one or both of @HD and @RG and that you want to eliminate those lines?

You said: "It is basically everything from the @HD up to the @RG.", but you didn't keep the space(s) before the %RG that were present in your input.

Please given us a clearer description of what you are trying to do and show us what you have tried.

What operating system and shell are you using?

Last edited by rbatte1; 07-03-2015 at 06:03 AM.. Reason: Corrected ICODE tag spelling
# 3  
Old 07-02-2015
Hi cmccabe,

Don is absolutely right.
However, you can try this if it helps
Code:
 sed -n 's/^\(@HD.*\)@RG.*/\1/p' file.txt


Last edited by rbatte1; 07-03-2015 at 06:02 AM.. Reason: Changed ICODE tags to CODE tags
# 4  
Old 07-03-2015
It depends on the split point. What is the rule you want to use?
  • Line length (truncate)
  • Number of fields
  • Specific delimiter - single character or string
  • Multiple delimiters e.g. after the 10th @
  • Something else Smilie
If you can explain how you want to work with the data, then we can work something out, but a single line input doesn't give us the rule clearly.


Thanks, in advance,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to create sub directories from specific file extension

In the bash below I am trying to create sub-directories inside a directory from files with specific .bam extensions. There may be more then one $RDIR ing the directory and the .bam file(s) are trimmed (removing the extension and IonCode_0000_) and the result is the folder name that is saved in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Programming

JAVA code to create file in Linux with specific permission

Hi All, I'm looking for JAVA code to create file in Linux with specific permission File should be created and saved in Linux in this path \opt\sys\doc by Java with this permission 764 Anyone can help to provide this Java code (3 Replies)
Discussion started by: AbuAliiiiiiiiii
3 Replies

3. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Create automated scan of specific directory using bash

I am trying to use bash to automate the scan of a specific directory using clamav. Having this in place is a network requirement. The below is an attempt to: 1. count the extensions (.txt, .jpeg) in a directory and write them to a virus-scan.log (section in bold) 2. scan each folder in the... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

Create a specific bash to increase the automatic update on my pi

hi everyone, I just began to be interested about the bash access. I buy a time ago a Raspberry pi, I installed raspbmc and now I would like build a bash to copy everyday all new files inside my server directly on the hard drive in my Pi. So my HDD is directly plug on my pi with usb connect,... (4 Replies)
Discussion started by: nagito34
4 Replies

6. UNIX for Dummies Questions & Answers

Create File with specific Length

We have utility running on Unix which generates Files with records greater than 32760 , (max supported by Mainframe) .Our requirement is to transfer is file to Mainframe .When we ftp the in binary format it automatically wraps it up..so we are good there... But now we need to zip and send the file... (2 Replies)
Discussion started by: nishantrk
2 Replies

7. AIX

create file and name it with same output name !

Guy's I have this command echo $? when I type it in AIX it will showme 0 I want when I type that command to create file in the same location with the same output of echo $? For exampl : I will execute the command now .... P_server/root/echo $? 0 the output is 0 so I want... (2 Replies)
Discussion started by: Mr.AIX
2 Replies

8. Shell Programming and Scripting

Need help in writing a script to create a new text file with specific data from existing two files

Hi, I have two text files. Need to create a third text file extracting specific data from first two existing files.. Text File 1: Format contains: SQL*Loader: Release 10.2.0.1.0 - Production on Wed Aug 4 21:06:34 2010 some text ............so on...and somwhere text like: Record 1:... (1 Reply)
Discussion started by: shashi143ibm
1 Replies

9. Solaris

create user with RWX access to a specific directory in Solaris 10

I need to create a user account for a developer that will allow him rwx access to all resources in a directory. How can I do that? Thanks (5 Replies)
Discussion started by: gsander
5 Replies

10. UNIX for Dummies Questions & Answers

how to create output like this

currently i have two clients connecting to my wifi router in telnet router, i typed the command : ~# dumpleases then it showed as following: Hostname Mac Address IP-Address billfan 00:15:00:15:c1:7e 192.168.11.100 00:16:cf:47:e7:ab... (4 Replies)
Discussion started by: billfanyang
4 Replies
Login or Register to Ask a Question