Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Shell script with sed

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-12-2009
Member
 
Join Date: Jul 2009
Posts: 140
Shell script with sed

Hello
I have an amendment to a file and I do not know how to manage the spaces or tabs in a row
In short: I try to modify a line that would word1 word2 and word3 separated by spaces or tabs to add mot4 him to finish. Any idea how to accomplish it? Thank you in advance.
Reply With Quote
  #2  
Old 23-12-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Shell script with sed

Hi
Quote:
Any idea how to accomplish it?
I think you can use the following line of code to complete you program.
Code:
sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt
Reply With Quote
  #3  
Old 23-12-2009
Member
 
Join Date: Jul 2009
Posts: 140
Re: Shell script with sed

Hi
Quote:
sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt
Thanks for the part of the code. But till now I have this with me
Code:
sed '/ password / s /.*/& Test' system
I have not really tried you part of code, but I will soon.
Reply With Quote
  #4  
Old 23-12-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Shell script with sed

Hello
Quote:
sed-i-e 's / ^ \ (arg1. * arg2 \ ).*$/& 1 ADD / g' file.txt
1 - / ^ \ (arg1. * arg2 \ ).*$/
- From the beginning of line ^
- I put in a buffer inside the expression contained in parentheses: \ (\). Attention is to precede the brackets \.
- I'll just end of line .* $ (any character repeated zero )

2 - & 1 ADD
- I copy buffer1: & 1
- And add ADD: ADD

when I reread it could even change the order in
Code:
sed-i-e 's / ^ \ (arg1. * arg2 .* \) $ / & 1 ADD / g' file.txt
Any more query do post back.
Reply With Quote
  #5  
Old 23-12-2009
Member
 
Join Date: Jul 2009
Posts: 140
Re: Shell script with sed

Hi
I want to add the line after the first line that starts with password. I found nothing better than:
Quote:
sed-i '/ ^ .* password requisite / a \ test' system
I had to add a second word to recognize the line.
We can not well avoid it? for it does not add as many as there is line beginning with password.
Reply With Quote
  #6  
Old 23-12-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Shell script with sed

Hello
Quote:
s / regexp / replacement /
Attempt to match regexp in the workspace. If successful, replace with the replacement part that is. The replacement may contain the special character & to refer to that portion of the workspace that match, and special characters \ 1 through \ 9 to refer to sub expressions, matched with regexp matching.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Shell script with sed"
Thread Thread Starter Forum Replies Last Post
shell script SSH not working Lilya Software Development 9 16-10-2010 02:53 AM
Creating shell script in ubuntu Elizabeth Allen Operating Systems 5 24-03-2010 02:35 PM
Shell script to add the extension to doc and pdf files Tailor Software Development 4 24-02-2010 10:51 PM
Shell Script Formatting abhi701 Software Development 1 04-07-2009 05:30 PM
Unix Shell Script BlackSunReyes Software Development 3 12-08-2008 02:57 PM


All times are GMT +5.5. The time now is 04:11 AM.