The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file manipulation teodora Shell Programming and Scripting 5 07-04-2008 02:52 AM
File manipulation with awk dhams Shell Programming and Scripting 6 08-24-2007 06:38 AM
File manipulation blackjack101 UNIX for Dummies Questions & Answers 5 06-11-2007 07:37 PM
File Manipulation kris01752 UNIX for Advanced & Expert Users 1 08-31-2006 11:55 AM
file name Manipulation using sed Zak Shell Programming and Scripting 6 03-14-2005 03:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-03-2008
Registered User
 

Join Date: Jul 2008
Posts: 3
file manipulation help please

Hi there,

I've trawled all over the web for help, and although seen some examples of what i want to do, I cannot seem to get it to work. I need to have this as a script.

If anyone can help, I would like to do the following: I have 2 files, File A and File B. I would like to keep file A but do a few manipulations to it.

In FILE A, I would like to replace a search patterns ##DATE_RUN## with the date, and where it says, ##BBG-DATA##, i would like that replaced with the contents of File B.

e.g.

File A

START-OF-FILE
DATERUN=##DATE_RUN##
REQUESTFILE=BBG_FILE.REQ

BBG-DATA-START
##BBG-DATA##
BBG-DATA-END

File B

index03
index04
index05
index06


The result of this would have File A containing:

START-OF-FILE
DATERUN=20080307
REQUESTFILE=BBG_FILE.REQ

BBG-DATA-START
index03
index04
index05
index06
BBG-DATA-END

Any help greatly appreciated!!!
Reply With Quote
Forum Sponsor
  #2  
Old 07-03-2008
Registered User
 

Join Date: Jul 2008
Posts: 3
Woops,
I am doing this in Unix.
Reply With Quote
  #3  
Old 07-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
What have you tried so far? You should post that.

Here is a hint,

Code:
awk 'BEGIN{ "date" | getline; printf "%s\n%s\n%s\n\n%s", "START-OF-FILE", $0, "REQUESTFILE=BBG_FILE.REQ", "BBG-DATA-START" } { print } END{ printf "%s\n", "BBG-DATA-END" }' filename
Reply With Quote
  #4  
Old 07-04-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 216
Or

Code:
awk -v d="$(date "+%Y%m%d")" -F= 'NR==FNR{a[NR]=$0;next}$1=="DATERUN"{print $1 FS d}/##BBG-DATA##/{for(i in a) print a[i]}$1!="DATERUN" && !/##BBG-DATA##/' File_B File_A
If file B is bigger than what's posted, then to preserve the order of the lines of that file B in the final output use

Code:
awk -v d="$(date "+%Y%m%d")" -F= 'NR==FNR{a[NR]=$0;c=FNR; next}$1=="DATERUN"{print $1 FS d}/##BBG-DATA##/{for(i=1;i<=c;i++) print a[i]}$1!="DATERUN" && !/##BBG-DATA##/' File_B File_A

Output

Code:
START-OF-FILE
DATERUN=20080704
REQUESTFILE=BBG_FILE.REQ

BBG-DATA-START
index03
index04
index05
index06
BBG-DATA-END
Change the date format as desired.

Last edited by rubin; 07-04-2008 at 11:04 AM.
Reply With Quote
  #5  
Old 07-04-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Code:
#!/bin/ksh93

while read line
do
   case $line in
      ~(E)##DATE_RUN##$ )
          print "DATERUN=$(date "+%m%d%Y")"
          ;;
      +(##BBG-DATA##) )
          cat fileB
          ;;
      *)
          print $line
          ;;
   esac
done < fileA
Reply With Quote
  #6  
Old 07-07-2008
Registered User
 

Join Date: Jul 2008
Posts: 3
cheers for the input guys ..

on Friday .. I played around with Sed, and came up with this .. what do u think? it seems to work ok so far ..

Code:
parm1="##RUN_DATE##"
parm2="##BBG_DATA##"

sed -e "s/$parm1/$RUN_DATE/" -e "/$parm2/r $BBG_4PM_HOME_PATH/$bbg_data" -e "/^$parm2/ d" $BBG_4PM_HOME_PATH/$bbg_template > $BBG_4PM_REQUEST_PATH/$bbg_request_file;

Last edited by radoulov; 07-07-2008 at 02:41 AM. Reason: added code tags
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0