LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2011, 07:47 AM   #16
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by grail View Post
Was there something wrong with my solution?
I couldnt get it to work because I was just tryng to replace Trans. The Port was out of the file I was trying to process. Is there any way we could adjust it?

Quote:
awk '/TRANSLATION/;if(/TRANSLATION/)getline < "v.head"}g' verses.txt > out.txt
awk: /TRANSLATION/;if(/TRANSLATION/)getline < "v.head"}g
awk: ^ syntax error
awk: /TRANSLATION/;if(/TRANSLATION/)getline < "v.head"}g
awk: ^ syntax error
 
Old 05-20-2011, 07:51 AM   #17
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by crts View Post
That is because you FILE is supposed to be the filename. Replace FILE with the actual name of your second file.
If you want to store the filename in a variable then you will have to use double-quotes instead of single-quotes to enable expansion. Like this

Code:
#!/bin/bash

patternFILE=v.head
workFILE=verses.txt
sed -n "/Trans/,/Port/{/Trans/ {R $patternFILE
d};/Port/! p}" $workFILE > out.txt
Can we edit the command?
Quote:
sed -n "/TRANSLATION/{/TRANSLATION/ {R v.head
d};p}" verses.txt > out1.txt

OUTPUT of ^:
Bg1.1
Bg1.2
Bg1.3
Quote:
TRANSLATION

Dhṛtarāṣṭra said: O Sañjaya, after assembling in the place of pilgrimage
at Kurukṣetra, what did my sons and the sons of Pāṇḍu do, being desirous
to fight?

TRANSLATION

Sañjaya said: O King, after looking over the army gathered by the sons
of Pāṇḍu, King Duryodhana went to his teacher and began to speak the
following words:
Quote:
Bg1.1

Dhṛtarāṣṭra said: O Sañjaya, after assembling in the place of pilgrimage
at Kurukṣetra, what did my sons and the sons of Pāṇḍu do, being desirous
to fight?

Bg1.2

Sañjaya said: O King, after looking over the army gathered by the sons
of Pāṇḍu, King Duryodhana went to his teacher and began to speak the
following words:

Last edited by brainAcid; 05-20-2011 at 07:54 AM.
 
Old 05-20-2011, 07:56 AM   #18
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Try this:
Code:
sed "/Trans/ {R $patternFILE
d}" $workFILE > out.txt
 
1 members found this post helpful.
Old 05-20-2011, 07:58 AM   #19
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Much Appreciated!

Ok Got it to work!!

THANKS!

Quote:
sed '/TRANSLATION/{/TRANSLATION/ {R v.head
d}}' verses.txt > out1.txt
 
Old 05-20-2011, 08:19 AM   #20
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by brainAcid View Post
Ok Got it to work!!

THANKS!
You are welcome. Please mark the thread as solved:
Thread tools -> mark as solved
 
Old 05-20-2011, 09:32 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
In case you were interested. You have put extra semi colon where the first curly brace is supposed to be, but as the Port part is no longer required this could be even simpler:
Code:
awk '/TRANSLATION/{getline < "v.head"}1' verses.txt
 
1 members found this post helpful.
Old 05-20-2011, 10:19 AM   #22
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Wink

Quote:
Originally Posted by grail View Post
In case you were interested. You have put extra semi colon where the first curly brace is supposed to be, but as the Port part is no longer required this could be even simpler:
Code:
awk '/TRANSLATION/{getline < "v.head"}1' verses.txt
Once again thanks to all for your effort!!

=)

Very happy with this community!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
text processing and cutting eliote Programming 3 10-26-2010 03:28 AM
Text-processing and loops ... skipdashu Linux - Newbie 10 04-30-2009 09:51 PM
text processing, maintaining a log jonhewer Linux - Newbie 9 08-25-2005 02:24 AM
text editingor processing exodist Linux - General 2 11-29-2003 10:24 PM
text processing Gantrep Linux - General 4 02-17-2003 10:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration