Need Help with sed/perl !


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help with sed/perl !
# 1  
Old 04-13-2011
Error Need Help with sed/perl !

In a file the content is
Code:
13 box google unix.com "he is google" hello "he is unix.com" -

I need to replace each space char with "a" char but not inside the double quoted strings.

So, the output must look like,
Code:
13aboxagoogleaunix.coma"he is google"ahelloa"he is unix.com"a-


I tried with
Code:
sed -e 's/[^"a-z0-9A-Z"]/a/g'

But this doesn't work. Please help.

Last edited by Franklin52; 04-14-2011 at 03:22 AM.. Reason: Please use code tags
# 2  
Old 04-13-2011
Try:
Code:
perl -F'"' -anle 'for ($i=0;$i<=$#F;$i+=2){$F[$i]=~s/ /a/g}print join "\"",@F' file

# 3  
Old 04-13-2011
Code:
echo "13 box google unix.com \"he is google\" helo \"he is unix.com\" -" |
awk -v p=1 '/\"/{p++}{printf p%2?$0"a":$0" "}' RS=" " 
 13aboxagoogleaunix.coma"he is google"ahelloa"he is unix.com"a-

# 4  
Old 04-13-2011
Error Thank you..but

Thank you all for replying. The awk command worked for me.

But, I am applying for a script starting with "cat <file>" and piping it to the one I explained.

example:
Code:
cat <file_name> | the awk command

The file has n number of lines in it. So for all these n number of lines I need to apply. So I used "cat" command. And after making the changes permanently in the file I need to pipe it again for removing double quotes in it.

An excerpt of a line is present as
Code:
13.13.4.3 Googe.com - Jan/23/2011:00:00:00 +0000 "URL Google HTTP/1.1" 45 56 208  - "http://www.gogle.com/webhp?hl=en&tab=nw#hl=en&source=hp&biw=1366&bih=667&q=hello&aq=f&aqi=&aql=&oq=&fp=c432485467934a89" ".Net; Fox" -


This is present in "n" number of lines. Please help.

Last edited by Franklin52; 04-14-2011 at 03:22 AM.. Reason: Please use code tags
# 5  
Old 04-14-2011
In the future, please detail the entire problem in the original post. Withholding information only to divulge it at a later step is inefficient. Knowing everything up front helps everyone avoid wasting time crafting incomplete solutions which may very well need to be modified when more information is provided.

In this case, the solutions provided can surely be tweaked to remove the quotes.

Regards,
Alister
# 6  
Old 04-14-2011
Error But it is complicated r8 ?

For IP address & URL's it is not working.So I gave extra details to it. Please help
# 7  
Old 04-14-2011
Code:
$ ruby -ne 'puts $_.split(/\"/).each_with_index{|x,y|x.gsub!(/\s+/,"") if y.even?}.join("\"")' file
13.13.4.3Googe.com-Jan/23/2011:00:00:00+0000"URL Google HTTP/1.1"4556208-"http://www.gogle.com/webhp?hl=en&tab=nw#hl=en&source=hp&biw=1366&bih=667&q=hello&aq=f&aqi=&aql=&oq=&fp=c432485467934a89"".Net; Fox"-

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rewrite sed to perl or run sed in perl

I am having trouble re-writing this sed code sed -nr 's/.*del(+)ins(+).*NC_0{4}(+).*g\.(+)_(+).*/\3\t\4\t\5\t\1\t\2/p' C:/Users/cmccabe/Desktop/Python27/out_position.txt > C:/Users/cmccabe/Desktop/Python27/out_parse.txt in perl Basically, what the code does is parse text from two fields... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Perl sed question

Hi, I'm trying to use perl the way I use sed. Lets say I have this command: $ echo abc | sed 's/abc/&&/' abcabcIf I try this with perl, I end up with this: $ echo abc | perl -pe 's/abc/&&/' &&How do I make the '&' sign work? Another thing that I can't get with perl is this: $ echo... (4 Replies)
Discussion started by: Subbeh
4 Replies

3. Shell Programming and Scripting

awk sed perl??

Hi guys First of all a salute to this wonderful platform which has helped me many a times. Im now faced with something that I cannot solve. I have data like this 11:14:18 0.46975 11:14:18 0.07558 11:14:18 0.00020 11:14:18 0.00120 11:14:18 0.25879 11:14:19 0.00974 11:14:19 0.05656... (13 Replies)
Discussion started by: jamie_123
13 Replies

4. Shell Programming and Scripting

re-Substitution Sed (or Perl)

I have a large text csv file that I'm working with. It will look something like this: D,",E",C O,"F,",I O,gh,R The second column always has a two digit random code (can be numbers, letters or any characters). When one of the characters happens to be a comma, the string is quoted. I want to... (5 Replies)
Discussion started by: beenny
5 Replies

5. Shell Programming and Scripting

Sed/Perl help

Some text is like this.... <table>This is first text.</table>mouse <table>This is second text</table>keyboard <table>This is third text</table>Pad I need to insert <a></a> between "mouse","keyboard","Pad". I it possible to do with sed/Perl ? Please help.. The text should look like... (8 Replies)
Discussion started by: gameboy87
8 Replies

6. Shell Programming and Scripting

Problem with sed in perl!!

Hi, I am facing an issue with sed in perl. I have a file which has 2 header lines and one trailer line. I need to process the file without these headers and trailer. My file looks like : File.txt:- Header1 Header2 data1 data2 trailer For removing header and trailer from file I am using... (5 Replies)
Discussion started by: abhisharma23
5 Replies

7. Shell Programming and Scripting

Convert sed to perl

Can anyone convert this from sed to perl: sed -n '/\var\/log/p' /etc/syslog.conf I think Ive looked at this to much....urgh.. Thanks Ben (5 Replies)
Discussion started by: bigben1220
5 Replies

8. UNIX for Advanced & Expert Users

Use of SED in Perl or any other options

Hi Folks, I am working on a data extraction script in perl.I am a begineer in perl and shell scripting. So i need your inputs to solve the script problem. I have data coming from database in the format :- <b> _ABC (Apply Changes) (p) </b> _EFG | HIJ | KLM | WER <b> _E3R (Apply Changes)... (3 Replies)
Discussion started by: subhotech
3 Replies

9. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

10. Shell Programming and Scripting

Perl/Sed script help

Hi All, I would need to generate Oracle Inster scripts from an excel formatted spreadsheet as follows: This needs to be stripped as follows: REC 1, REC 2 etc are the separators of the records ... I beleive a pearl script can be written for this ... anything useful will be of... (8 Replies)
Discussion started by: sabyasm
8 Replies
Login or Register to Ask a Question