?
Solved

How to append string??

Posted on 2004-09-16
15
Medium Priority
?
1,362 Views
Last Modified: 2007-12-19
i want to append the string at the beggining of the file. (i.e) in the first line

i want to append the string 'test document' at the begining of the file.

I am using Korn shell.

Thanks in advance
0
Comment
Question by:delphipal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
15 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 1000 total points
ID: 12078670
sed -e '1 s/\(.*\)/test document\n\1/' yourfile > file.new && mv file.new yourfile

Or

echo "test document" > file.new
cat yourfile >> file.new
mv file.new yourfile
0
 
LVL 1

Expert Comment

by:shyampaliyath
ID: 12078982
thanks a lot but how to leave aline after the 'test document'  word i want the rest of the documents lines to prnted in the next line
0
 
LVL 1

Expert Comment

by:shyampaliyath
ID: 12079034
please one more quick question how to do this procedure for a group of files

thanks a lot for this help
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 20

Assisted Solution

by:dsacker
dsacker earned 1000 total points
ID: 12079497
for item in `find * -type f`; do
    (work with $item in your code)
done
0
 
LVL 1

Expert Comment

by:shyampaliyath
ID: 12079580
i have stored in the file abc.ksh

for item in 'find * -type f'; do
echo $item
done

how do i execute it?? i know that this question is bit simple but i am new to UNIX
0
 
LVL 20

Expert Comment

by:dsacker
ID: 12079694
chmod 755 abc.ksh

You should then be able to simply type "abc.ksh" (without the quotes)
0
 
LVL 1

Expert Comment

by:shyampaliyath
ID: 12079827
ok but if i go for

for item in 'find samp* -type f'; do
echo $item
done

$item returns as ' find sample.ls sample.lst -type f
and not indvidually as sample.lst and sample.ls

i tried using
for item in 'find samp* -type f'; do
echo $item
done

but return as 'samp* sample.ls sample.lst'
and not indvidually as sample.lst and sample.ls
0
 
LVL 21

Expert Comment

by:tfewster
ID: 12079911
To answer your second question:
If you want to use sed, add another \n  (carriage return) to the "substitute" sting; If you're using the `cat ` method, just put another line in, `echo "" >> file.new` to insert a blank line.

To clarify on the third question:
You're using single-quotes ( ' ) instead of the backticks ( ` ) dsacker told you to use;  Single quotes mean 'Pass this string as the parameter'; Backticks mean `execute this command and use the results as the input`

http://www.experts-exchange.com/Community_Support/help.jsp#hi107
http://www.experts-exchange.com/Community_Support/Q_21134342.html
0
 
LVL 1

Expert Comment

by:shyampaliyath
ID: 12079979
Thanks for ur answer

For ur first link "I Aplogise" becoz i got doubts as and when i got the answer. And I make sure that i will be more careful.

But for ur second link I strongly object after all whoever ask the question points will be awarded for the answer by the person who intiated this and two person if they get the same doubt cannot post same question twice. AM I RIGHT.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 12080141
> But for ur second link I strongly object...

I reported something that looks suspicious - If I'm wrong, I'll apologise to both of you. Even so, abandoned questions are a major problem, and I can imagine delphipal forgetting to close this question because "shyampaliyath was dealing with it".

Actually, I'll apologise now for my first "complaint" about multiple-questions;  For 500 points, you certainly  have the right to ask for clarifications and revise the original question to some extent.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 12085745
You can split the points yourself now - Click on "Split ponts" just above the comment box
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question