LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2015, 05:40 AM   #1
QWE123
Member
 
Registered: Nov 2014
Posts: 55

Rep: Reputation: Disabled
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
 
Old 08-04-2015, 06:05 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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

Last edited by HMW; 08-04-2015 at 06:08 AM.
 
Old 08-04-2015, 08:49 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
I am curious what this had to do with 'change date content' as this was the subject?
 
Old 08-04-2015, 11:01 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by grail View Post
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.
 
Old 08-04-2015, 10:34 PM   #5
QWE123
Member
 
Registered: Nov 2014
Posts: 55

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by HMW View Post
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
 
Old 08-05-2015, 02:26 AM   #6
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by QWE123 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Maildir++: set file date from email content iwbnwif Linux - Server 0 10-04-2014 03:44 PM
Change the content of files but not change the date ust Linux - Newbie 1 12-17-2012 10:48 AM
LXer: How to change Thunderbird's date format in Date column LXer Syndicated Linux News 0 07-18-2012 02:11 AM
How to set date time using a file content yaadgiri Linux - Newbie 4 01-13-2010 10:58 PM
delete a file based on content and date ElectroLinux Linux - Newbie 7 08-19-2009 07:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration