![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!!! |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Woops,
I am doing this in Unix. |
|
#3
|
|||
|
|||
|
What have you tried so far?
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
|
|
#4
|
||||
|
||||
|
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
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 Last edited by rubin; 07-04-2008 at 11:04 AM. |
|
#5
|
|||
|
|||
|
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
|
|
#6
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |