- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Appending Text to End of 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
Discussions
Discussions
Discussions
Forums
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
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
тАО11-24-2003 05:54 PM
тАО11-24-2003 05:54 PM
Appending Text to End of File
I have 10 text files in a directory. I need to apped some text( in file x) to all the files. COuld you please help me achieve this,
I am doing it this way
cat file >> * . This is creating a file *.
Your help is greatly appreciated.
Thanks,
Nag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 05:59 PM
тАО11-24-2003 05:59 PM
Re: Appending Text to End of File
Tried this before ?
cat filex >> file1
cat filex >> file2
.....
Rgds
Alexander M. Ermes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 06:23 PM
тАО11-24-2003 06:23 PM
Re: Appending Text to End of File
Do a script that you can call appendfile.sh
then:
cat filex >> file1
cat filex >> file2
cat filex >> file3
and so on....
chmod 755 appendfile .sh
then execute the file.
./appendfile.sh
//Tommy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 07:36 PM
тАО11-24-2003 07:36 PM
Re: Appending Text to End of File
for f in f1 f2 f3 f4 f5 f6 f7 f8 f9 f10
do
cat x >> $f
done
Where f1-f10 are your file names.
Or, if your 10 files patch a pattern, (eg *.txt), use
for f in *.txt
do
cat x >> $f
done
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 11:04 PM
тАО11-24-2003 11:04 PM
Re: Appending Text to End of File
the shell does no expansion of things like * after a redirection >. Graham has the simplest solution.
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 11:14 PM
тАО11-24-2003 11:14 PM
Re: Appending Text to End of File
#!/usr/bin/ksh
filedir=/dir_where_files_are
files=$(ls $filedir | grep -v fileX)
cat $filedir/fileX >> $files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 11:28 PM
тАО11-24-2003 11:28 PM
Re: Appending Text to End of File
#!/usr/bin/ksh
filedir=/dir_where_files_are
files=$(ls $filedir | grep -v fileX)
for i in $files
do
cat $filedir/fileX >> $i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-24-2003 11:33 PM
тАО11-24-2003 11:33 PM
Re: Appending Text to End of File
ignore the post above... this one is better
#!/usr/bin/ksh
filedir=/dir_where_files_are
files=$(ls $filedir | grep -v fileX)
for i in $files
do
cat $filedir/fileX >> $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-26-2003 03:19 AM
тАО11-26-2003 03:19 AM
Re: Appending Text to End of File
The simplest way to append a string of test to the end of an existing file is to use the echo command.
echo "text to append" >> file
Using the cat command requires that you create a new file with your text to append.
If the directory contains just the 10 files that you want to append to, then you can do the following:
for i in *
do
echo "text to append" >> $i
done
JL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2003 12:20 AM
тАО11-27-2003 12:20 AM
Re: Appending Text to End of File
if the problem is solved, could you spare some points from the endless supply of points, HP has, for those, who could help you? ;-)
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-27-2003 07:21 PM
тАО11-27-2003 07:21 PM
Re: Appending Text to End of File
Considering that the files are only 10, i think to commands manually.
With the command "vi" (or "ed" or "ex") you extract the part of text from the fileX and saves it in fileY.
# vi fileX
Then with the command "cat" you append fileY to all the files.
# cat filey > > file1
# cat filey > > file2
# cat filey > > file3
(...repeat for all files)
You can avoid repetition by using a script with cicle "for".
Like explanation by others answers previous (of others user).
HTH
Bruno