Enter data at end of a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Enter data at end of a file
# 1  
Old 12-31-2009
Enter data at end of a file

Hi All,

I have a sample datafile:

Code:
 
5.1
5.2
0.8
6.1

What I want to do is create an additional 3 rows with the number "0.7". so that I now have:

Code:
 
5.1
5.2
0.8
6.1
0.7
0.7
0.7

Can someone help...thanks
# 2  
Old 12-31-2009
Tools Many ways to accomplish

You could create sample2.txt (with vi editor, for instance) which would include
0.7
0.7
0.7

And then
Code:
cat sample.txt sample2.txt

which would display to screen, or
Code:
cat sample.txt sample2.txt >newsample.txt

which writes the combined output to new file called newsample.txt
# 3  
Old 12-31-2009
Code:
echo "0.7
0.7
0.7" >> sample_data_file

# 4  
Old 01-01-2010
Thanks guys.
my problem is a little bit complicated because my datafile contains hundreds of rows, so I couldn't possibly create a blank file and fill it up by hand as suggested by joeyg. But your suggestions have helped in the sense that I've arrived at a solution.

I used the echo command in a loop to get the result I wanted.
Code:
#!/bin/sh
#
echo -n "enter file.. "; read file
for ((i=1; i<=7; i++)); do
echo "0.7" >> $file
done
exit

thanks guys!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value File 1 export SERVER_CONNECTION=//dvlna002:10001/SmartServer File2 export SERVER_CONNECTION=///SmartServer File3 export... (1 Reply)
Discussion started by: Nsharma3006
1 Replies

2. Shell Programming and Scripting

Script to prompt user to enter data

Hi All I have a script that moves files from one dir to another dir based on date, but I would like to change it in a way that whoever is going to run to enter the dates in which files will be removed. This is my script: #!/bin/sh touch -mt 201302250000 /tmp/ref3 touch -mt 201302282359... (14 Replies)
Discussion started by: fretagi
14 Replies

3. UNIX for Dummies Questions & Answers

TWO QUESTIONS...How to create your own command in UNIX server,How to enter data in a file by script

I am a quite newbie on UNIX SCRIPTING...Please help me solving this two questions... 1st Question; I want to create one command that will run a script when anyone use that command on that server... I mean, in the prompt if I put my name 'Rony' it will execute a script called 'rony.sh'. How can... (1 Reply)
Discussion started by: Rony-123
1 Replies

4. Shell Programming and Scripting

append | to the end of each data in a file

I have a file which has data in the below format: 7810902|6783014102| || |0| |0| |0| |0|||||T|04/13/2006||9423|7421||100|2006-04-13 16:50:28|||2006-04-13 16:50:28|n|51|-1||214 1089929|||||NewSpCreateAction request successful. Activity ID = <826528>||||100|n|2006-04-13 16:50:27|2006-04-13... (3 Replies)
Discussion started by: ankianand88
3 Replies

5. Shell Programming and Scripting

How to enter a newline after every XML tag end?

Hi Guyz, I have an XML message in following format: I want my contents to be formatted in following order: i.e. I want a newline after every XML tag end. How to do this? Thnx in advance. (5 Replies)
Discussion started by: DTechBuddy
5 Replies

6. UNIX for Advanced & Expert Users

Create a file and enter data in columns

Hello!!!!!!!! I have an issue regarding inserting records in a file columnwise.Is it possible using awk/nawk script? Example: File1: 1|AAA|25|2 5|qqe|20|7 4|wer|31|81 I need to create a second file in which data can be inserted in a columnwise manner i.e. File2: AAA|25|1|2... (1 Reply)
Discussion started by: abhijeet1409
1 Replies

7. Programming

unable to get end of file while reading HTTP data from socket

I am trying to read HTTP data from a socket. However, for the final set of data being read using read(), read blocks and the control doesnt come back for further processing. I tried using select, but it didn't work... Any help would be greatly acknowledged.:) (2 Replies)
Discussion started by: Harish.joshi
2 Replies

8. Shell Programming and Scripting

How to get rid of extra enter at the end???

Hi guys, I want to automate a few tasks. For one of them, I need to get the output of a command and parse it to extract information I need: drbdadm create-md drbd0 The output is: md_offset 48010952704 al_offset 48010919936 bm_offset 48009453568 Found ext2 filesystem which uses... (2 Replies)
Discussion started by: alirezan
2 Replies

9. UNIX for Dummies Questions & Answers

add data from command line to end of file

how can I add data from command line to end of file? (3 Replies)
Discussion started by: bryan
3 Replies
Login or Register to Ask a Question