Sponsored Content
Full Discussion: Insert character in the line
Top Forums UNIX for Dummies Questions & Answers Insert character in the line Post 302329999 by swat on Tuesday 30th of June 2009 02:14:57 AM
Old 06-30-2009
Network Insert character in the line

Hi All,

I have below type file.

abc|asd|pqr|2|2|2
asc|qwe|scf|5|4|4

Pipe location and count is dynamic and coming from a variable.
I want to change it to below files.
(chnage the first pipe to 3 pipes)
abc|||asd|pqr|2|2|2
asc|||qwe|scf|5|4|4
(chnage the second pipe to 4 pipes)
abc|asd||||pqr|2|2|2
asc|qwe||||scf|5|4|4

It should be dynamic.
Smilie
Thanks,
SWAT
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk insert character in the middle of a line

I'm trying to insert a single character at position 11 in everyline of a file. My input file looks like this: 456781 ~Y~12345 456782 ~N~12300 and I want my output to look like this: 45678~1 ~Y~12345 45678~2 ~N~12300 I tried the following awk code, but it's not working:... (3 Replies)
Discussion started by: mmarino
3 Replies

2. Shell Programming and Scripting

How to insert a character in line in Special condition?

Hi, I have a log file generated by a tool which has the following look : /tmp/releases/directory/datefilename1_release_date.zip /tmp/releases/directory/datefilename2_release_date.zip /tmp/releases/directory/datefilename3_release_date.zip... (8 Replies)
Discussion started by: bhaskar_m
8 Replies

3. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

4. Shell Programming and Scripting

insert character in particular position.

I want to insert space in 7th position of all the lines usign vi editor or sed command Input file 12345689010 abcdefghijk . . Output file 123456 89010 abcdef ghijk . . (7 Replies)
Discussion started by: Jairaj
7 Replies

5. Shell Programming and Scripting

sed to insert a character

Hi all, I have a file like this Q8N302 21-84 Q8N157 15-45 Q99996 167-201 202-251 269-318 I want to insert a character or space if the line starts with a number and I used the command sed 's/^/#/' But in the output file, when it inserts this character, first digit in the number is... (2 Replies)
Discussion started by: kaav06
2 Replies

6. Shell Programming and Scripting

Insert a character before a line

I have a file and I can get the line with a specific pattern. I want to inset # on start of the line. file.text ==== aa bb cc bb hh kk kk ll yy dd aa kk rr tt aa I want to comment out the line with contain "aa" after running the script file.text ==== #aa bb cc bb hh kk kk ll... (7 Replies)
Discussion started by: Biplab
7 Replies

7. Shell Programming and Scripting

Insert New Line Character

Hi, If my first character of a line starts with 2 then after 5th charecter newline character should be inserted. Input.txt: a1234567890 2222300007 bsdfsdf888999999 ssdfkjskfdjskfdjd 2899900000000099999999999999 28887777 999999999999999999 Output.txt: a1234567890 22223 00007... (8 Replies)
Discussion started by: unme
8 Replies

8. UNIX for Dummies Questions & Answers

Insert sign every n character (awk)

Hi, For example, I would like to insert a pipe every 4 characters for each second field (including after the last block). input (coma separated): line1,AAAABBBBCCCCDDDDEEEE line2,FFFFGGGGHHHHIIIIJJJJ output: line1,AAAA|BBBB|CCCC|DDDD|EEEE| line2,FFFF|GGGG|HHHH|IIII|JJJJ| my... (2 Replies)
Discussion started by: beca123456
2 Replies

9. Shell Programming and Scripting

Insert character at specific location in a each line of the file

Hi All, I am trying to write a shell script where it should insert character 'I' in 180th position of each line(except first and last line) of the file. Below is the script for file in /home/test/bharat/*.RET do # Process file echo "File Name=" $file #l_fileName="${file##*/}" ... (19 Replies)
Discussion started by: bharath561989
19 Replies

10. UNIX for Beginners Questions & Answers

How to insert new line after a specific character in scripts?

Hi, I'm trying to add a new line after finding a specific String. That is my string: volumes: - ${DIR_WORK}/loadbalancer/html:/var/www/html and I want to change that file to: volumes: - ${DIR_WORK}/loadbalancer/html:/var/www/html extra_hosts: -... (4 Replies)
Discussion started by: siamak
4 Replies
SCF(3pm)						User Contributed Perl Documentation						  SCF(3pm)

NAME
Bio::SCF - Perl extension for reading and writting SCF sequence files SYNOPSIS
use Bio::SCF; # tied interface tie %hash,'Bio::SCF','my_scf_file.scf'; my $sequence_length = $hash{bases_length}; my $chromatogram_sample_length = $hash{samples_length}; my $third_base = $hash{bases}[2]; my $quality_score = $hash{$third_base}[2]; my $sample_A_at_time_1400 = $hash{samples}{A}[1400]; # change the third base and write out new file $hash{bases}[2] = 'C'; tied (%hash)->write('new.scf'); # object-oriented interface my $scf = Bio::SCF->new('my_scf_file.scf'); my $sequence_length = $scf->bases_length; my $chromatogram_sample_length = $scf->samples_length; my $third_base = $scf->bases(2); my $quality_score = $scf->score(2); my $sample_A_at_time_1400 = $scf->sample('A',1400); # change the third base and write out new file $scf->bases(2,'C'); $scf->write('new.scf'); DESCRIPTION
This module provides a perl interface to SCF DNA sequencing files. It has both tied hash and an object-oriented interfaces. It provides the ability to read fields from SCF files and limited ability to modify them and write them back. Tied Methods $obj = tie %hash,'Bio::SCF',$filename_or_handle Tie the Bio::SCF module to a filename or filehandle. If successful, tie() will return the object. $value = $hash{'key'} Fetch a field from the SCF file. Valid keys are as follows: Key Value --- ----- bases_length Number of called bases in the sequence (read-only) samples_length Number of samples in the file (read-only) version SCF version (read-only) code_set Code set used to code bases (read-only) comments Structured comments (read-only) bases Array reference to a list of the base calls index Array reference to a list of the sample position for each of the base calls (e.g. the position of the base calling peak) A An array reference that can be used to determine the probability that the base in position $i is an "A". G An array reference that can be used to determine the probability that the base in position $i is a "G". C An array reference that can be used to determine the probability that the base in position $i is a "C". T An array reference that can be used to determine the probability that the base in position $i is a "T". samples A hash reference with keys "A", "C", "G" and "T". The value of each hash is an array reference to the list of intensity values for each sample. To get the length of the called sequence: $scf{bases_length} To get the value of the called sequence at position 3: $scf{bases}[3] To get the sample position at which base 3 was called: $scf{index}[3] To get the value of the "C" curve under base 3: $scf{samples}{C}[$scf{index}[3]] To get the probability that base 3 is a "C": $scf{C}[3] To print out the chromatogram as a four-column list: my $samples = $scf{samples}; for (my $i = 0; $i<$scf{samples_length}; $i++) { print join " ",$samples->{C}[$i],$samples->{G}[$i], $samples->{A}[$i],$samples->{T}[$i]," "; } $scf{bases}[$index] = $new_value The base call probability scores, base call values, base call positions, and sample values are all read/write, so that you can change them: $samples->{C}[500] = 0; each %scf Will return keys and values for the tied object. delete $scf{$key} %scf = () These operations are not supported and will return a run-time error Object Methods $scf = Bio::SCF->new($scf_file_or_filehandle) Create a new Bio::SCF object. The single argument is the name of a file or a previously-opened filehandle. If successful, new() returns the Bio::SCF object. $length = $scf->bases_length Return the length of the called sequence. $samples = $scf->samples_length Return the length of the list of chromatogram samples in the file. There are four sample series, one for each base. $sample_size = $scf->sample_size Returns the size of each sample (bytes). $code_set = $scf->code_set Return the code set used for base calling. $base = $scf->base($base_no [,$new_base]) Get the base call at the indicated position. If a new value is provided, will change the base call to the indicated base. $index = $scf->index($base_no [,$new_index]) Translates the indicated base position into the sample index for that called base. Here is how to fetch the intensity values at base number 5: my $sample_index = $scf->index(5); my ($g,$a,$t,$c) = map { $scf->sample($_,$sample_index) } qw(G A T C); If you provide a new value for the sample index, it will be updated. $base_score = $scf->base_score($base,$base_no [,$new_score]) Get the probability that the indicated base occurs at position $base_no. Here is how to fetch the probabilities for the four bases at base position 5: my ($g,$a,$t,$c) = map { $scf->base_score($_,5) } qw(G A T C); If you provide a new value for the base probability score, it will be updated. $score = $scf->score($base_no) Get the quality score for the called base at the indicated position. $intensity = $scf->sample($base,$sample_index [,$new_value]) Get the intensity value for the channel corresponding to the indicated base at the indicated sample index. You may update the intensity by providing a new value. $scf->write('file_path') Write the updated SCF file to the indicated file path. $scf->fwrite($file_handle) Write the updated SCF file to the indicated filehandle. The file must previously have been opened for writing. The filehandle is actually reopened in append mode, so you can call fwrite() multiple times and interperse your own record separators. EXAMPLES
Reading information from a preexisting file: tie %scf, 'Bio::SCF', "data.scf"; print "Base calls: "; for ( my $i=0; $i<$scf{bases}; $i++ ){ print "$scf{base}[$i] "; } print " "; print "Intensity values for the A curve "; for ( my $i=0; $i<$scf{samples}; $i++ ){ print "$scf{sample}{A}[$i]; } print " "; Another example, where we set all bases to "A", indexes to 10 and write the file back: my $obj = tie %scf,'Bio::SCF','data.scf'; for (0...@{$scf{bases}}-1){ $scf{base}[$_] = "A"; $obj->set('index', $_, 10); } $obj->write('data.scf'); AUTHOR
Dmitri Priimak, priimak@cshl.org(1999) with some cleanups by Lincoln Stein, lstein@cshl.edu(2006) This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER for disclaimers of warranty. SEE ALSO
perl(1). perl v5.14.2 2009-08-17 SCF(3pm)
All times are GMT -4. The time now is 12:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy