Solved

How to append string??

Posted on 2004-09-16
15
1,351 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
  • 5
  • 4
  • 2
  • +1
15 Comments
 
LVL 20

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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 20

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 20

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 20

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now