- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Challenging Script question
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
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
тАО04-18-2006 04:20 AM
тАО04-18-2006 04:20 AM
Line1
Line2
Line3
Line4
Line5
Im trying to write a script that takes two arguments. The first being a line of text and the second the name of the file above. How do I insert the first argument(line of text) into the first line of the file named above.
For example:
./scriptTest Hello this is a test File1
Would append File1 as such:
Hello this is a test
Line1
Line2
Line3
Line4
Line5
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 04:25 AM
тАО04-18-2006 04:25 AM
Re: Challenging Script question
filename=$2
(echo $header ;cat $filename) > /tmp/mytmpfile
mv /tmp/mytmpfile $filename
one of the ways how to do it..
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 04:26 AM
тАО04-18-2006 04:26 AM
Re: Challenging Script question
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 04:26 AM
тАО04-18-2006 04:26 AM
Re: Challenging Script question
echo $1 > /tmp/file
cat $2 >> /tmp/file
cp /tmp/file $2
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 04:32 AM
тАО04-18-2006 04:32 AM
Re: Challenging Script question
Using the shell only:
cat ./insertit
#!/usr/bin/sh
echo "${1}" >> "${2}.new"
cat ${2} >> "${2}.new"
mv "${2}.new" "${2}"
# ./insert it ok yourfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 04:47 AM
тАО04-18-2006 04:47 AM
Re: Challenging Script question
So far I have managed the following.
sed -e '1i\' -e "$*" > File1
But this appends the whole line including the second argument.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 05:00 AM
тАО04-18-2006 05:00 AM
Re: Challenging Script question
f=$1
t=/tmp/hold$$
shift
echo $* | cat - $f >$t
mv $t $f
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 05:01 AM
тАО04-18-2006 05:01 AM
Re: Challenging Script question
echo hello this is a test file1 | awk '{
for(i=1;i
}'
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 05:03 AM
тАО04-18-2006 05:03 AM
Re: Challenging Script question
The line of text has to come first then the file name.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2006 05:10 AM
тАО04-18-2006 05:10 AM
Re: Challenging Script question
Im not sure that will work. How does the script know to echo the line of text: Hello this is a test, unless you manually type it in the script.
It could be any line of text.