Moving a part of the text in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Moving a part of the text in a file
# 1  
Old 05-04-2009
Moving a part of the text in a file

***************
#some other text

*****************
[unicast]


***************
#some other text

*****************
address1=1.1.1.1
address2=2.2.2.2
address3=3.3.3.3



I have a file where i need to push all the text starting from address1 till end of file to, below [unicast]. Can anyone of you help?? Thanks for the solution. I tried getting the line number of the [unicast]. But it was of no use. Also i need to delete it after i move the text.

Last edited by srikanthgoodboy; 05-04-2009 at 10:07 AM..
# 2  
Old 05-04-2009
Hi
You can use this sample of code:
PHP Code:
APP_CONF=./myfile.txt
NEW_FILE
=./NewFile.txt
WANTED_STRING
="address"
awk -F";" '{print $1}' $APP_CONF | while read RAW
 
do
  if [[ 
$RAW == $WANTED_STRING* ]] then
   
echo $RAW>> $NEW_FILE
  fi
 done 
or simply, you can use this command:
PHP Code:
 grep "address" ./myfile.txt newFile.txt 
Cheers
# 3  
Old 05-04-2009
Thank you very much Smilie for the immediate response.

I wanted a script command and also after putting address1 and following text below [unicast] i need to delete it.
# 4  
Old 05-04-2009
grep "address" ./myfile.txt > newFile.txt
cat myfile.txt | grep -v address > myfile1.txt
mv myfile1.txt myfile.txt


put these three lines in a file and run it, probably it will work.
# 5  
Old 05-04-2009
it did not work Smilie
# 6  
Old 05-04-2009
Quote:
Originally Posted by srikanthgoodboy
it did not work Smilie
What is your expected o/p from the i/p file you have given above?


cheers,
Devaraj Takhellambam
# 7  
Old 05-04-2009
wats the issue?? any error??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Renaming part of a text file ?

I have several files that are named like this "DotP_D14 - Verknüpfung" They all have the " - Verknüpfung" in common. I'd like to rename all of them to get rid of that last part. Is this possible with DOS on windows ? (1 Reply)
Discussion started by: pasc
1 Replies

2. Shell Programming and Scripting

To display the selected part in text file of unix

0400903071220312 20120322 20:21 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS 182644 000C2 8122011 0000 000 1TRANTELSTRAFLEXCAB22032012CMP201323930000812201108875802100A003485363 12122011AUS ... (6 Replies)
Discussion started by: rammm
6 Replies

3. Shell Programming and Scripting

search needed part in text file (awk?)

Hello! I have text file: From aaa@bbb Fri Jun 1 10:04:29 2010 --____OSPHWOJQGRPHNTTXKYGR____ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline My code '234565'. ... (2 Replies)
Discussion started by: candyme
2 Replies

4. Shell Programming and Scripting

extract part of text file

I need to extract the following lines from this text and put it in different files. From xxxx@gmail.com Thu Jun 10 21:15:46 2010 Return-Path: <xxxxx@gmail.com> X-Original-To: xxx@localhost Delivered-To:xxxx@localhost Received: from ubuntu (localhost ) by ubuntu (Postfix) with ESMTP... (11 Replies)
Discussion started by: waxo
11 Replies

5. Shell Programming and Scripting

Remove part of a column in a text file

I have a text file with delimiter "|" and sometimes the zipcode is in "5th" column or "6th" column. I want to scan the file and remove the "-2323" from the zipcode which has zip+4 digits From blah|blah|foo|bar||blah|945523-232|USA blah|blah|foo|bar||blah|foo|94555-2323|USA To... (8 Replies)
Discussion started by: gubbu
8 Replies

6. Shell Programming and Scripting

moving text within file

I want to mvoe lines around in a file. Say I have 30 lines in a file and want to move the last 5 lines to the top of the file..how can this be done? i thought of awk and sed but was not sure context. please assist thanks (5 Replies)
Discussion started by: sigh2010
5 Replies

7. Shell Programming and Scripting

extracting part of a text file

Hi guys So I have a very large log file where each event is logged along with the time that it occurred. So for e.g. The contents of the file look like: ... 12:00:07 event 0 happened. 12:01:01 event 1 happened. 12:01:05 event 2 happened. 12:01:30 event 3 happened. 12:02:01 event 4... (10 Replies)
Discussion started by: alinaqvi90
10 Replies

8. Shell Programming and Scripting

Get the latest added part of a text file?

Hi, I want to get the latest added part of a text file sent over the network to for analysis. Is there a tool to use to keep track of which part of a text file that has already been analysed so only the "new" lines will be sent and handled? I have checked a few tools but I still don´t know how to... (3 Replies)
Discussion started by: pcrs
3 Replies

9. UNIX for Dummies Questions & Answers

moving apache part 2

Hi everybody..... please help me in moving apache 2.2 over to another server remotely............. still having problems thank you (12 Replies)
Discussion started by: marinob007
12 Replies

10. Shell Programming and Scripting

Moving part of Text in a file

Hi, I have this text in a file where I need to move part of the text.... <Relation1 OriginatingObjectID="Holding_1" RelatedObjectID="Party_1" id="Relation_1"> <OriginatingObjectType tc="4">Holding</OriginatingObjectType> <RelatedObjectType tc="6">Party</RelatedObjectType>... (4 Replies)
Discussion started by: mgirinath
4 Replies
Login or Register to Ask a Question