Replacement of sed with perl

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacement of sed with perl
# 1  
Old 01-25-2008
Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line .

For example my input file consists of

out put file consists of
I am achieving the above requirement using sed as below

sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' file

but i have thousands of files in one directory its consuming more and more time .

Can anyone replace the above requirement in perl with xargs

like xargs perl option

cn anyone suggest the easiest way without looping
# 2  
Old 01-25-2008
how about sed:
sed -e :a -e '/$;/N; s/\\\n//; s/$;//; ta'  oldfile > newfile

# 3  
Old 01-25-2008
Hi Jim ,

The above code works with sed but it is consuming too much time ..can you provide the same with perl syntax.
THe functionality is it has to identify last character in each line of all files as semicolon.if it founds as semicolon it has to replace with blank space otherwise need to append next line with present one.
# 4  
Old 01-25-2008
see your other thread
# 5  
Old 01-25-2008
cn anyone provide me the solution for replacing sed with perl in the above
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Word replacement in Perl

I have the following string : Cat dog fox catepillar bear foxy I need to replace "cat" and "fox" words from this sentence to word "animal" I do the following: $Str1="cat"; $Str2="fox"; $NewStr="animal"; open(F1, "<$inputFile") or die "Error: $!"; open(F2, ">$outputFile") or... (1 Reply)
Discussion started by: AIX_30
1 Replies

2. Shell Programming and Scripting

SED replacement

Hi, i have a file with lines, file.txt ------- test is fun testing is better I need to replace 'test' to 'develop' and i used, a=test b=develop sed "s,$a,$b,g" -------- but i see the word 'testing' is also replaced. Need some solution. Is there any way i could replace only 'test' ? (4 Replies)
Discussion started by: giri_luck
4 Replies

3. Shell Programming and Scripting

Replacement with sed

I am trying to replace the line which has string "tablespace" not case senstive.... with below simple script: sed "s/.*/TABLESPACE USERS/g" create_table > tmp mv tmp create_table Is there any better way to do it? If Search string tooooooo long it will be tough to code in... (4 Replies)
Discussion started by: ganeshd
4 Replies

4. Shell Programming and Scripting

Help with sed replacement

This seems like it should be an easy problem, but I'm a noob and I can't figure it out. I'm trying to use sed, but would be happy to use anything that does the job. I am trying to trim off a fixed number of unknown characters from 2 different : delimited fields while keeping the intervening... (4 Replies)
Discussion started by: helix_w
4 Replies

5. Shell Programming and Scripting

HELP Need in SED/PERL conditional line replacement

Hi , I need some help on perl/sed conditional replacement The situation is like below . I have a file contents like below . AAA|BBB|CCC|DDD AAA|BCF|CCC|HHH AAA|BVF|JJJ|KKK Here in the above file . I know my second column value (taking "|" as my delimited ) Basically I have to... (3 Replies)
Discussion started by: robin.r888
3 Replies

6. Shell Programming and Scripting

Replacement of sentence in perl

Hi, I have 3 arrays: @arr1=("Furthermore, apigenin treatment increased the level of association of the RNA binding protein HuR with endogenous p53 mRNA","one of the mechanisms by which apigenin induces p53 protein expression is enhancement of translation through the RNA binding protein... (1 Reply)
Discussion started by: vanitham
1 Replies

7. Shell Programming and Scripting

Replacement for eval in Perl??????

I used the eval command in shell programming for assigning a value to a stored value of a variable. Example: VAR="Unix_Id" eval $VAR="101" eval echo $"$VAR" How can i assign a value to a stored value of a variable in perl OR how i can write above code in Perl? I need your help... (4 Replies)
Discussion started by: kunal_dixit
4 Replies

8. Shell Programming and Scripting

Need Replacement for sed

Hi Can anyone provide me the replacement of sed with xargs perl syntax for the below sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' This should be without looping has to take minimal time for search (0 Replies)
Discussion started by: dbsurf
0 Replies

9. Shell Programming and Scripting

String Replacement with Perl

I want to replace a string within a file using perl. We have a line that gets commented out, and I want to replace that line now matter how it was commented out. for example, I'd want to replace ###ES=PR1A with ES=PR1A or ##LJW(9/16/26)ES=PR1A with ES=PR1A I tried: perl... (4 Replies)
Discussion started by: Lindarella
4 Replies

10. UNIX for Dummies Questions & Answers

Replacement using sed

Hi I have the following file that i need to run a sed command on 1<tab>running 2<tab>running 3<tab>running 4<tab>running I want to be able to replace a line i.e the second one with '2<tab>failed'. As the first number is unique that can be used to search for the relevant line (using ^2 i... (5 Replies)
Discussion started by: handak9
5 Replies
Login or Register to Ask a Question