LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2013, 11:38 AM   #1
karthik1asr
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Rep: Reputation: Disabled
Question regarding awk or sed to find and replace a word in Solaris for Scripting


Hi all,

This is my first question at this forum. I am a newbie to shell scripting. I have any issue in finding a string and replacing it in shell scripting.

So here is my Text in the Input file and I have only one line in the file:

^^file=2013-03-26 13:08:01.214 04:00||^^header=64||2||AUE_SYSTEMBOOT||na||solaris-bsm-team2||2013-03-26 13:07:41.014 -04:00^^text=booting kernel^^header=54||2||AUE_init_solaris||na||solaris-bsm-team2||2013-03-26 13:08:01.675 -04:00^^text=booted^^return=success||0^^header=97||2||AUE_login||||solaris-bsm-team2||2013-03-26 13:08:19.811 -04:00^^subject=master||master||staff||master||staff||1166||2386485855||0 0 solaris-bsm-team2^^return=success||0

Now I need to replace all the occurrences of the string "^^header" and replace it with "\nheader" where \n is new line.

Can someone please help how to write it, so that i can use it as a part of my script.

Thanks in advance.

Best Regards

Last edited by karthik1asr; 03-29-2013 at 11:41 AM. Reason: word change
 
Old 03-29-2013, 11:48 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Just try following:
Code:
~$ awk '{gsub(/\^\^header/,"\nheader",$0); print $0}' infile.txt
OR
~$ sed -e 's/\^\^header/\nheader/g' infile.txt

Last edited by shivaa; 03-29-2013 at 11:49 AM.
 
1 members found this post helpful.
Old 03-29-2013, 11:55 AM   #3
karthik1asr
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi Shivaa,

thank you so much for the reply. you saved my time. The awk command just worked like a beauty.

I was trying until now like this::

awk '{gsub(\^\^header/,\nheader,$0); print $0}'

It didnt work. Thanks again man!!
 
Old 03-29-2013, 12:40 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
You are welcome!

Please Mark the thread as solved (option is under Thread Tools on top menu), if you think it has so.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Find/Replace shell script that replaces word with other word in text, filenames yanom Programming 8 09-12-2012 01:29 AM
awk, sed find and replace recursively from files bluewind Linux - Newbie 17 02-26-2010 11:06 AM
Multi-line find/replace with GnuWin32 Sed Question EdrickV Programming 4 04-26-2009 02:32 PM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 03:55 AM
sed or awk question - replace caps with small letters computera Linux - General 1 12-30-2003 05:39 AM


All times are GMT -5. The time now is 10:21 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration