Solved

How to append string??

Posted on 2004-09-16
15
1,357 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 250 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
Independent Software Vendors: 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!

 
LVL 20

Assisted Solution

by:dsacker
dsacker earned 250 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
 

Author Comment

by:delphipal
ID: 12085696
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
text in table need to be center of the box 4 86
need to remove or skip  grub protection password in ubuntu on boot time 2 90
Sed question 2 139
Access_log 17 183
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

732 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