Solved

How to append string??

Posted on 2004-09-16
15
1,359 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
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!

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

691 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