LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   change date content (https://www.linuxquestions.org/questions/programming-9/change-date-content-4175549802/)

QWE123 08-04-2015 05:40 AM

change date content
 
I have a file , the content as below.

#vi file
Code:

xxx Warning yyy zzz 111
xxx yyy Warning zzz 111
xxx yyy zzz Warning 111

what I would like to do is to change the words after the word Warning to "Please ignore" , so that the output becomes as below , would advise how to write the script ? thanks

Code:

xxx Warning Please ignore
xxx yyy Warning Please ignore
xxx yyy zzz Warning Please ignore


HMW 08-04-2015 06:05 AM

Hi!

This sed seems to do the trick:
Code:

echo "xxx Warning yyy zzz 111
xxx yyy Warning zzz 111
xxx yyy zzz Warning 111" | sed 's/\(.*Warning\).*/\1 Please ignore/g'
xxx Warning Please ignore
xxx yyy Warning Please ignore
xxx yyy zzz Warning Please ignore

Best regards,
HMW

grail 08-04-2015 08:49 AM

I am curious what this had to do with 'change date content' as this was the subject?

HMW 08-04-2015 11:01 AM

Quote:

Originally Posted by grail (Post 5400715)
I am curious what this had to do with 'change date content' as this was the subject?

I took it for a typo. Probably should be "change data content". If not, then I am at a loss as well.

QWE123 08-04-2015 10:34 PM

Quote:

Originally Posted by HMW (Post 5400758)
I took it for a typo. Probably should be "change data content". If not, then I am at a loss as well.

thanks reply , it works,

one more question , if I have 10 files need to be update , would advise how can I bulk update these files and directly update it rather than output to screen ?

Thanks

HMW 08-05-2015 02:26 AM

Quote:

Originally Posted by QWE123 (Post 5401005)
one more question , if I have 10 files need to be update , would advise how can I bulk update these files and directly update it rather than output to screen ?

Thanks

Check out sed -i
Code:

-i[SUFFIX], --in-place[=SUFFIX]
    edit files in place (makes backup if extension supplied). The default operation mode is to break symbolic and hard links. This can be changed with --follow-symlinks and --copy.

...to change the files 'in place'.

Best regards,
HMW


All times are GMT -5. The time now is 01:34 PM.