- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- appending in the middle of the file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2002 06:29 AM
07-29-2002 06:29 AM
appending in the middle of the file
Before I send email in my script I need to remove first 3 lines and I also need to add one paragraph after words Dear Name, e.g.
Current format:
yara
yara
yars
Dear Name,
hello1
hello2
Needed Format:
Dear Name
hello0 // new paragraph is added
hello1
hello2
I know how to remove first three lines, but how can I append a paragraph?
Here is my code in Perl:
$rc = 0xffff & system("tail +3 $FILENAME | mailx -s \"$mailSubject\" $adminMail ");
Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2002 06:39 AM
07-29-2002 06:39 AM
Re: appending in the middle of the file
cat $PARAGRAPH > $NEWLETTER
awk '{if (NR>3) print $0}' $OLDLETTER >> $NEWLETTER
Regards,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2002 06:42 AM
07-29-2002 06:42 AM
Re: appending in the middle of the file
open(INP,"<$FILENAME") or die "no open $FILENAME";
open(OUT,"|mailx -s \"$mailSubject\") or die "no open mailx";
while(
next if $. <= 3;
print OUT $_;
print OUT "hello0 // new paragraph is added\n" if /^Dear Name/;
}
close(INP); close(OUT);
Hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2002 10:28 AM
07-29-2002 10:28 AM
Re: appending in the middle of the file
I used this crude method to insert, at a given line in a file, a string.
string="* FAILURE IN $SCRIPT_NAME ON $HOST CALL $PROGRAMMER"
ed << EOF
e /path_to/file_name
4i
$string
.
w /path_to/file_name
q
I suppose $string could be your paragraph. In this example it is inserted at line 4 of /path_to/file_name.
Hope this helps.
Best of Luck.
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2002 04:49 AM
07-31-2002 04:49 AM
Re: appending in the middle of the file
Call this script:
#!/bin/ksh
in_file=$1 # File to be split
parse_string="$2" # String to Parse
para_file=$3 # File with new paragraph
new_file=$4 # Output file
split_file=`mktemp` # Holds the split data in two files
csplit -s -f ${split_file} ${in_file} /"${parse_string}"/+1 # Split the file
cat ${split_file}00 > ${new_file}
cat ${para_file} >> ${new_file}
cat ${split_file}01 >> ${new_file}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2002 05:20 AM
07-31-2002 05:20 AM
Re: appending in the middle of the file
sed -n 4p file1 > sendfile
echo hello0 >> sendfile
sed -n 5,6p >> sendfile
You'll have to change the 6 to however long your file is, or otherwise get it dynamically by using:
fileLength=`nl -ba file1 | tail -1 | awk '{print $1}'`
and then change the last bit to be
sed -n 5,"$fileLength"p >> sendfile
Cheers!
James