- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to append data to the first line in a 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
01-08-2007 05:46 AM
01-08-2007 05:46 AM
Script to append data to the first line in a file
We need to generate a script which will append to first line in a file in the 100th position.
We have an ASCII file generated from the ERP system. The ASCII file can have n number of lines in it. We need to append some contents to the first line in the file before processing the file further.
Every flat file will have an identifier in the first line. For example: Purchase order will have “Purchase Order” as the first line. BOL will have “Bill of Lading” as identifier in the first line. We need to append the string “PRINTER:
Request your help in writing the script.
Regards,
Usha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 05:53 AM
01-08-2007 05:53 AM
Re: Script to append data to the first line in a file
I believe that this is answered here:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1088911
Please see my last post therein.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 06:30 AM
01-08-2007 06:30 AM
Re: Script to append data to the first line in a file
Thanks a lot for the quick response.
But when I execute the script I get an error as follows:
Syntax error at line 3 : `{' is not expected.
What could be the possible error?
I am a novice in UNIX.
Regards,
Usha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 06:36 AM
01-08-2007 06:36 AM
Re: Script to append data to the first line in a file
I am sorry the error is on line 2.
Syntax error at line 2 : `{' is not expected.
Regards,
Usha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 06:49 AM
01-08-2007 06:49 AM
Re: Script to append data to the first line in a file
#!/usr/bin/sh
FILE=
TEXT=
FILET=/tmp/$(basename ${FILE}).tmp
echo "$(echo $(head -1 ${FILE}) $(perl -e 'print " "x100') | cut -c1-100)" ${TEXT} > ${FILET}
sed -n '2,$p' < ${FILE} >> ${FILET}
cp -f ${FILET} ${FILE}
exit 0
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2007 06:55 AM
01-08-2007 06:55 AM
Re: Script to append data to the first line in a file
If you cut-and-paste exactly this (from the post I referenced) into an empty file:
#!/usr/bin/perl -ni.old
if ( $. == 1 ) {
if ( length($_) < 100 ) {
chomp;
printf "%-100s%s\n", $_, "WORD";
}
else {
s/(.{100})(.*)/$1WORD$2/;
print;
}
next;
}
print;
...then having called the script "myfilter", you should do:
# ./myfilter myfile
...where "myfile" is the file to be changed.
If you added "#!/usr/bin/sh" at the top of the script, then that is your problem! Copy and paste exactly what I wrote.
Regards!
...JRF...