Sponsored Content
Full Discussion: remove and replace
Top Forums Shell Programming and Scripting remove and replace Post 302347482 by ppat7046 on Tuesday 25th of August 2009 09:17:56 PM
Old 08-25-2009
remove and replace

Hi Friends,

I have following string.
1:Y 2:Y 3:Y 4:Y 5:Y 6:N 7:N 8:Y 9:N 10:N 11:N 12:N 13:Y 14:Y 15:411

I need to have follwoing string.
'Y','Y','Y','Y','Y','N','N','Y','N','N','N','N','Y','Y','411'

Thank you,
Prashant
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove spaces between charc and replace it with ','.

Hi, Below is my output file: (The below line has multiple spaces bet charc and I want to replace spaces with "," only for the first line) NYCCMS97KJ931 01-JUN-08 1214957 I want this to be: ... (5 Replies)
Discussion started by: smc3
5 Replies

2. Shell Programming and Scripting

remove and replace text in a file

Hello all, How would I go to a particular line in a file and remove certain text from it and replace with something that I want it to be there. like: file /etc/abc now look for line HOME="/export/xyz" in /etc/abc and then replace with HOME=/"export/xyz1" thanks in advance guys. (1 Reply)
Discussion started by: solaix14
1 Replies

3. UNIX for Advanced & Expert Users

Locate text in file then remove and replace

I'm trying to locate a block of text in a file, remove it and then replace with a new block. I can find the first line number that the text starts on using grep -n. I then need to locate the ending line by searching for the string "}" that follows the line I found. Here's the steps I need to... (1 Reply)
Discussion started by: lchandle
1 Replies

4. Shell Programming and Scripting

Replace/Remove not specific text in perl

Hello, Consider that i have many files that have the below format: file1 900 7777 1000 5 6 23 nnnnnnnnnnnnnnnnnn 1100 kkkkkkk file2 900 1989 1000 5 3 10 kkkdfdfdffd 1100 kkkkkkk What i would like to do is on every file to search the line that starts with... (4 Replies)
Discussion started by: chriss_58
4 Replies

5. Solaris

Cannot remove and replace failed disk

-bash-3.00# zpool detach zonepool c1t1d0 cannot detach c1t1d0: only applicable to mirror and replacing vdevs -bash-3.00# zpool remove zonepool c1t1d0 cannot remove c1t1d0: only inactive hot spares, cache, top-level, or log devices can be removed -bash-3.00# zpool offline zonepool c1t1d0... (3 Replies)
Discussion started by: LittleLebowski
3 Replies

6. Shell Programming and Scripting

ksh Remove and replace repeated in file

Hi, i need to read a line from a file and count the number of times it appear in, then continuous to the second line with the same. So when i count a line i have to remove all duplicates in the file to not count it another time. while read line do n=$(grep -c $line File) print "$line... (5 Replies)
Discussion started by: ToniX
5 Replies

7. Shell Programming and Scripting

Remove/replace the very first character/symbol match

cat file.txt file 1123.x July 23:222 /cd/hh2/k39/ss2/f7d8d9d8e6r5t4s/dd2/e/s7a/s7a2afa5017d8b975-1.7-1395610245-b22e19bbc477b134 i wish to only extract out the 1.7 (anything within the first - -) i try to look for the sed command under match the first occurence of pattern but out of luck, my... (6 Replies)
Discussion started by: ctphua
6 Replies

8. UNIX for Dummies Questions & Answers

How to replace and remove few junk characters from a specific field?

I would like to remove all characters starting with "%" and ending with ")" in the 4th field - please help!! 1412007819.864 /device/services/heartbeatxx 204 0.547%!i(int=0) 0.434 0.112 1412007819.866 /device/services/heartbeatxx 204 0.547%!i(int=1) 0.423 0.123... (10 Replies)
Discussion started by: snemuk14
10 Replies

9. UNIX for Beginners Questions & Answers

Remove characters and replace with space

tr -cd '\11\12\15\40-\176' < file-with-binary-chars > clean-file This removes special characters but how can I replace it with space (4 Replies)
Discussion started by: eskay
4 Replies

10. UNIX for Beginners Questions & Answers

Remove first 3 leadings zeros and replace with space

Hi Folks - I need help manipulating a file. For column 2, I need to replace the first 3 leading zeros with spaces. The file looks like such: 00098|00011250000003|00000000000.0200|D|1|07|51|04INDP |04|00820|CS|000000|092717|000000000000.0000|000|... (3 Replies)
Discussion started by: SIMMS7400
3 Replies
Boulder::Stream(3pm)					User Contributed Perl Documentation				      Boulder::Stream(3pm)

NAME
Boulder::Stream - Read and write tag/value data from an input stream SYNOPSIS
#!/bin/perl # Read a series of People records from STDIN. # Add an "Eligible" tag to all those whose # Age >= 35 and Friends list includes "Fred" use Boulder::Stream; # filestream way: my $stream = Boulder::Stream->newFh; while ( my $record = <$stream> ) { next unless $record->Age >= 35; my @friends = $record->Friends; next unless grep {$_ eq 'Fred'} @friends; $record->insert(Eligible => 'yes'); print $stream $record; } # object oriented way: my $stream = Boulder::Stream->new; while (my $record = $stream->get ) { next unless $record->Age >= 35; my @friends = $record->Friends; next unless grep {$_ eq 'Fred'} @friends; $record->insert(Eligible => 'yes'); print $stream $record; } DESCRIPTION
Boulder::Stream provides stream-oriented access to Boulder IO hierarchical tag/value data. It can be used in a magic tied filehandle mode, as shown in the synopsis, or in object-oriented mode. Using tied filehandles, Stone objects are read from input using the standard <> operator. Stone objects printed to the tied filehandle appear on the output stream in Boulder format. By default, data is read from the magic ARGV filehandle (STDIN or a list of files provided on the command line) and written to STDOUT. This can be changed to the filehandles of your choice. Pass through behavior When using the object-oriented form of Boulder::Stream, tags which aren't specifically requested by the get() method are passed through to output unchanged. This allows pipes of programs to be constructed easily. Most programs will want to put the tags back into the boulder stream once they're finished, potentially adding their own. Of course some programs will want to behave differently. For example, a database query program will generate but not read a boulderio stream, while a report generator will read but not write the stream. This convention allows the following type of pipe to be set up: query_database | find_vector | find_dups | | blast_sequence | pick_primer | mail_report If all the programs in the pipe follow the conventions, then it will be possible to interpose other programs, such as a repetitive element finder, in the middle of the pipe without disturbing other components. SKELETON BOULDER PROGRAM
Here is a skeleton example. #!/bin/perl use Boulder::Stream; my $stream = Boulder::Stream->newFh; while ( my $record = <$stream> ) { next unless $record->Age >= 35; my @friends = $record->Friends; next unless grep {$_ eq 'Fred'} @friends; $record->insert(Eligible => 'yes'); print $stream $record; } The code starts by creating a Boulder::Stream object to handle the I/O. It reads from the stream one record at a time, returning a Stone object. We recover the Age and Friends tags, and continue looping unless the Age is greater or equal to 35, and the list of Friends contains "Fred". If these criteria match, then we insert a new tag named Eligible and print the record to the stream. The output may look like this: Name=Janice Age=36 Eligible=yes Friends=Susan Friends=Fred Friends=Ralph = Name=Ralph Age=42 Eligible=yes Friends=Janice Friends=Fred = Name=Susan Age=35 Eligible=yes Friends=Susan Friends=Fred = Note that in this case only records that meet the criteria are echoed to standard output. The object-oriented version of the program looks like this: #!/bin/perl use Boulder::Stream; my $stream = Boulder::Stream->new; while ( my $record = $stream->get('Age','Friends') ) { next unless $record->Age >= 35; my @friends = $record->Friends; next unless grep {$_ eq 'Fred'} @friends; $record->insert(Eligible => 'yes'); $stream->put($record); } The get() method is used to fetch Stones containing one or more of the indicated tags. The put() method is used to send the result to standard output. The pass-through behavior might produce a set of records like this one: Name=Janice Age=36 Eligible=yes Friends=Susan Friends=Fred Friends=Ralph = Name=Phillip Age=30 = Name=Ralph Age=42 Eligible=yes Friends=Janice Friends=Fred = Name=Barbara Friends=Agatha Friends=Janice = Name=Susan Age=35 Eligible=yes Friends=Susan Friends=Fred = Notice that there are now two records ("Phillip" and "Barbara") that do not contain the Eligible tag. Boulder::Stream METHODS $stream = Boulder::Stream->new(*IN,*OUT) $stream = Boulder::Stream->new(-in=>*IN,-out=>*OUT) The new() method creates a new Boulder::Stream object. You can provide input and output filehandles. If you leave one or both undefined new() will default to standard input or standard output. You are free to use files, pipes, sockets, and other types of file handles. You may provide the filehandle arguments as bare words, globs, or glob refs. You are also free to use the named argument style shown in the second heading. $fh = Boulder::Stream->newFh(-in=>*IN, -out=>*OUT) Returns a filehandle object tied to a Boulder::Stream object. Reads on the filehandle perform a get(). Writes invoke a put(). To retrieve the underlying Boulder::Stream object, call Perl's built-in tied() function: $stream = tied $fh; $stone = $stream->get(@taglist) @stones = $stream->get(@taglist) Every time get() is called, it will return a new Stone object. The Stone will be created from the input stream, using just the tags provided in the argument list. Pass no tags to receive whatever tags are present in the input stream. If none of the tags that you specify are in the current boulder record, you will receive an empty Stone. At the end of the input stream, you will receive undef. If called in an array context, get() returns a list of all stones from the input stream that contain one or more of the specified tags. $stone = $stream->read_record(@taglist) Identical to get(>, but the name is longer. $stream->put($stone) Write a Stone to the output filehandle. $stream->write_record($stone) Identical to put(), but the name is longer. Useful State Variables in a Boulder::Stream Every Boulder::Stream has several state variables that you can adjust. Fix them in this fashion: $a = new Boulder::Stream; $a->{delim}=':'; $a->{record_start}='['; $a->{record_end}=']'; $a->{passthru}=undef; o delim This is the delimiter character between tags and values, "=" by default. o record_start This is the start of nested record character, "{" by default. o record_end This is the end of nested record character, "}" by default. o passthru This determines whether unrecognized tags should be passed through from the input stream to the output stream. This is 'true' by default. Set it to undef to override this behavior. BUGS
Because the delim, record_start and record_end characters in the Boulder::Stream object are used in optimized (once-compiled) pattern matching, you cannot change these values once get() has once been called. To change the defaults, you must create the Boulder::Stream, set the characters, and only then begin reading from the input stream. For the same reason, different Boulder::Stream objects cannot use different delimiters. AUTHOR
Lincoln D. Stein <lstein@cshl.org>, Cold Spring Harbor Laboratory, Cold Spring Harbor, NY. This module can be used and distributed on the same terms as Perl itself. SEE ALSO
Boulder, Boulder::Blast, Boulder::Genbank, Boulder::Medline, Boulder::Unigene, Boulder::Omim, Boulder::SwissProt perl v5.10.1 2001-06-11 Boulder::Stream(3pm)
All times are GMT -4. The time now is 05:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy