modify a format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting modify a format
# 1  
Old 01-12-2011
modify a format

Hi I have a format that looks like this:

Code:
#TailType       TwoSided
#Scale to target        True
#Target Intensity       100
#Intensities    PM/MM
#Treatment CEL  ./G.CEL
#Control CEL    ./F.CEL
chr1    16      0
chr1    24      0
chr1    32      0.187188
chr1    40      0.14595
chr1    48      0.569928
chr1    56      1.05253
chr1    64      0.773825
chr1    72      0
chr1    80      0.0284669

What I want to do is delete all rows with # then have it so it looks like this:

Code:
chr1    16      24     0
 chr1    24      32     0
 chr1    32      40     0.187188
 chr1    40      48     0.14595
 chr1    48      56     0.569928
 chr1    56      64     1.05253
 chr1    64      72     0.773825
 chr1    72      80     0
 chr1    80      etc.         0.0284669


The file is tab deliminted.

It would be best if this can be written in Perl but awk is fine too.
# 2  
Old 01-12-2011
One of the sed and awk solution..
Code:
sed '/^#/d' inputfile > outfile
awk '!/^#/' inputfile > outfile

# 3  
Old 01-12-2011
thanks but there is still one more step Smilie
# 4  
Old 01-12-2011
Ah! i did'n notice that..
Code:
awk 'NR==FNR{a[FNR]=$2;next}!/^#/{print a[FNR+1]!=""?$1 FS $2 FS a[FNR+1] FS $3:$1 FS $2 FS "etc." FS $3}' inputfile inputfile > outfile


Last edited by michaelrozar17; 01-12-2011 at 05:08 AM.. Reason: typo
# 5  
Old 01-12-2011
try,
Code:
 
awk '!/^#/{if(a!=""){print a" "b" "$2" "c}a=$1;b=$2;c=$3;}END{print a" "b" etc "c}' inputfile > outfile

# 6  
Old 01-12-2011
A Perl adaptation of xoops solution:

Code:
#!/usr/bin/perl
   
open(DAT,shift) or die "Unable to open file \n";

foreach ( <DAT> ) {
   unless ( /^#/ ) {
      ($a,$b,$c)=split(/\s+/,$_);
      print "$A $B $b $C\n" if ( $B ne "" ) ;
      ($A,$B,$C)=($a,$b,$c);
      }
   }
print "$A $B etc. $C\n" if ( $A ne "" )  ;

close(DAT);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Grant unprivileged user rights to see the output of echo|format but not modify disks

anyone have any idea how do to this with auth_attr? I suspect if I grant him solaris.device.:RO::Device Allocation::help=DevAllocHeader.html that will work but I'm unsure. Just looking for a second opinion. (10 Replies)
Discussion started by: os2mac
10 Replies

2. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

3. Shell Programming and Scripting

Help to modify in Excel format

Hi I ran some query in solaris machine and the result of the query is as below. Result: dn: uid=xxx,dc=example,dc=com id: xxx firstname: sam lastname: nam But my question is , how to get result in excel format in solaris and result attributes dn,id,firstname,lastname values ... (1 Reply)
Discussion started by: buzzme
1 Replies

4. Homework & Coursework Questions

How to modify .NN format in UNIX to 0.NN (less than 0)?

Hi All, I have a query in unix shell script. The help which i was looking for is : I want to modify .NN format in unix shell script to 0.NN this is specific for the values which is less than 0. It would be great if this can be done by using sed or awk. Please let me know in case... (1 Reply)
Discussion started by: Karthik89
1 Replies

5. Shell Programming and Scripting

perl module to convert xlsx format to xls format

Hi Folks, I have written a perl script that reads data from excel sheet(.xls) using Spreadsheet::ParseExcel module. But the problem is this module doesn't work for excel sheets with extension .xlsx. I have gone through Spreadsheet::XLSX module with which we can read from .xlsx file directly.... (1 Reply)
Discussion started by: giridhar276
1 Replies

6. Shell Programming and Scripting

modify ls -l (long listing format output) strictly using SED only straightforward goalhard 4 me doh

Below is a sample out of ls -l which I would like to rearrange or modify by field numbers for example I successfully managed to disect using simple paragraph however for ls -l I can't divide the rows or fields by field number. Successful modification by fields using SED sample: $ sed -e... (1 Reply)
Discussion started by: wolf@=NK
1 Replies

7. Shell Programming and Scripting

Modify a perl line to parse out and output to another format

Hey there... I am looking for a way to take the below contents ( small excerpt) of this file called PTR.csv ptrrecord,0000002e0cc0.homeoffice.anfcorp.com,,10.11.191.62,,,False,62.191.11.10.in-addr.arpa,,302400,default... (6 Replies)
Discussion started by: richsark
6 Replies

8. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

10. Shell Programming and Scripting

List files and display last modify time in a particular format

hi everyone, can someone suggest how i can list the contents of a directory and display their corresponding last modify time in the format yyyymmddhhmm? thanks in advance! (16 Replies)
Discussion started by: Deanne
16 Replies
Login or Register to Ask a Question