- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: simple scripting help
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
09-16-2003 08:44 AM
09-16-2003 08:44 AM
I want to add one line of text to a flat file as a new first row and save the resulting file with the same name. My meager attempts at cat result in the text at the end of the file. I've tried various incarnations of cat and redirection with no success. I don't want to use cp or mv.
Text to add is 6-8 char long as a variable.
New Data:
$mydata = "mytext"
Original File:
$filename
Contents of $filename:
line1 of orig file
line2 of orig file
line3 etc etc etc
Desired contents resulting file to be saved as $filename:
mytext
line1 of orig file
line2 of orig file
line3 etc etc etc
Thanks in advance,
Doug
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2003 08:53 AM
09-16-2003 08:53 AM
Re: simple scripting help
There's certainly more elegant ways to do this, but a simple approach like this should work:
echo $mydate > somefile
cat $filename >> somefile
mv somefile $filename
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2003 08:54 AM
09-16-2003 08:54 AM
Re: simple scripting help
#!/usr/bin/sh
mydata="mytext"
echo $mydata > /tmp/file
cat /tmp/file $filename > /tmp/file1
mv /tmp/file1 $filename
rm /tmp/file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2003 08:54 AM
09-16-2003 08:54 AM
Re: simple scripting help
# echo $mydata > /tmp/newfile
# cat $filename >> /tmp/newfile
# mv /tmp/newfile $filename
--Sundar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2003 09:05 AM
09-16-2003 09:05 AM
Re: simple scripting help
maybe you can use this:
# TEXT="Hej Doug"
# echo "$TEXT" |cat - $filename
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2003 09:07 AM
09-16-2003 09:07 AM
SolutionJust answered similar yesterday i.e.
#!/usr/bin/ksh
# Test a prepend to file
# 1i means insert at line one.
echo "Keep on keeping on." | read STRING_TO_INSERT
string="$STRING_TO_INSERT"
ed << EOF >/dev/null
e /home/dlamar/work/test1.fil
1i
$string
.
w /home/dlamar/work/test1.fil
q
EOF
Best regards,
dl