Computing.Net > Forums > Unix > Append a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Append a file

Reply to Message Icon

Name: khanati
Date: June 17, 2004 at 07:56:28 Pacific
OS: UNIC
CPU/Ram: 256
Comment:

I have a file and i want to add some new stuff in the middle of that. How can i do that? Someone help me out. I want to write a script for that. I am using BASH.

Atif



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 17, 2004 at 09:02:22 Pacific
Reply:

Hi:

Your question is very general so I'm taking thefile line count dividing it by 2 and appending "my text" to newfile after counting that many lines:


#!/bin/bash

cnt=$(wc -l < thefile)
cnt=$((cnt/2))

ll=0
while read line
do
ll=$((ll+1))
if [[ $ll -eq $cnt ]]
then
echo "my newtext " >> newfile
else
echo "$line" >> newfile
fi
done < thefile


0

Response Number 2
Name: khanati
Date: June 17, 2004 at 09:43:16 Pacific
Reply:

i have a Makefile:

# This is a template for all makefile.

#Set the list of files to be delete by clean:
CLEAN_TARGETS += $(ALL_LIBRARIES)

#Set the list of target to make while testing
TEST_TARGETS += mytest

# adjust the location of Rules.mk as needed.
include ../../Rules.mk

mytest:
$(CMDECHO) echo mytest > /dev/null

testWithFailure:
ifeq ($(FAIL),)
$(WarnFailTest)
endif


I want to add comething from the command line in front of TEST_TARGETS +=

How can i do that.

Thanks for the reply.

Atif


0

Response Number 3
Name: khanati
Date: June 17, 2004 at 09:45:49 Pacific
Reply:

One more thing.

there is 'mytest' after TEST_TARGETS +=

i need to delete that in one option and i want to retain that in another, for example if i get 'test1' from command line it should be appeneded so that it becomes
TEST_TARGETS += test1 mytest

atif



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Append a file

appending a newline eof www.computing.net/answers/unix/appending-a-newline-eof/7256.html

appending few lines to a file www.computing.net/answers/unix/appending-few-lines-to-a-file/7522.html

Editing a file without awk or sed www.computing.net/answers/unix/editing-a-file-without-awk-or-sed/5437.html