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
Solved

How to append string??

Posted on 2004-09-16
15
1,355 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.

860 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