LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 08:47 AM   #16
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 15

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, 08:51 AM   #17
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 15

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 08:54 AM.
 
Old 05-20-2011, 08:56 AM   #18
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

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

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, 09:19 AM   #20
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,620

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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, 10:32 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
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, 11:19 AM   #22
brainAcid
LQ Newbie
 
Registered: May 2011
Posts: 15

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 04:28 AM
Text-processing and loops ... skipdashu Linux - Newbie 10 04-30-2009 10:51 PM
text processing, maintaining a log jonhewer Linux - Newbie 9 08-25-2005 03:24 AM
text editingor processing exodist Linux - General 2 11-29-2003 11:24 PM
text processing Gantrep Linux - General 4 02-17-2003 11:37 PM

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

All times are GMT -5. The time now is 03:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration