LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2019, 07:28 AM   #1
meromero25
LQ Newbie
 
Registered: Aug 2019
Posts: 2

Rep: Reputation: Disabled
How can I use sed to generate an awk file?


How do I write sed commands to generate an awk file.

Here is my problem: For example, I have a text file, A.txt which contains a word on each line.

app#
#ple
#ol#

The # refers when the word starts/ ends/ starts and ends. For example, app# shows that the word starts with 'app'. #ple shows that the word ends with 'ple'. #ol# shows that the word has 'ol' in the middle of the word.

I have to generate an awk file from sed commands which reads in another file, B.txt (which contains a word on each line) and increments the variable start, end, middle.

How do I write sed commands whereby for each line in the text file, A.txt, it will generate an awk code ie.

{ {if ($1 ~/^app/)
{start++;}
}

For example, if I input the other file, B.txt with these words into the awk script,

application
people
bold
cold

The output would be; start = 1, end = 1, middle = 2.
 
Old 08-12-2019, 07:33 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,962

Rep: Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089
Welcome here!

Based on the rules of LQ:
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
Please show what have you written so far, where did you stuck or what kind of help do you need.
 
Old 08-12-2019, 07:33 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,013

Rep: Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884Reputation: 2884
Such a ridiculous requirement sounds like homework. See the LQ rules.
 
Old 08-12-2019, 07:44 AM   #4
meromero25
LQ Newbie
 
Registered: Aug 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
I'm new to sed so I have no idea where to start. I tried searching for how to generate awk script from sed script but nothing useful popped up. I just need a hint so that I can begin.
 
Old 08-12-2019, 07:55 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 12,962

Rep: Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089Reputation: 4089
so first try to create an awk by hand (which would be [finally] generated).
 
  


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
[SOLVED] sed inside awk or awk inside awk maddyfreaks Linux - Newbie 4 06-29-2016 01:10 PM
Trying to use awk to generate a report petemac117 Linux - Newbie 4 02-28-2014 11:02 AM
request to generate a awk file for NS2 .tr file vin.18 Linux - Networking 1 02-09-2013 09:07 AM
[SOLVED] Once again... awk.. awk... awk shivaa Linux - Newbie 13 12-31-2012 04:56 AM
[SOLVED] use awk &/or sed to read file 1 line 1 & file 2 line 1 gr8scot Linux - General 6 07-12-2007 08:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:26 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