LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-25-2008, 03:30 PM   #1
TsanChung
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Rep: Reputation: 0
parse input text file and generate output


Given a text file input, what program will change it to the following
output?
The input has the '/' character and has no space (blank) character in
each line.

Rules are:
1. add "%dir /usr/hw/" to lines not ending in 'L', 'H', 'I', 'L' or
'S'.
2. add "%attr(0444,root,root) /usr/hw/" to lines ending in 'L', 'H',
'I' or 'L'.
3. add "%attr(0544,root,root) /usr/hw/" to lines ending in 'S'.
4. add "mkdir -p " to the "longest" unique path of the output of rule
1.

Please help.
Thanks.

Input 1:
Cabc/Cde
Cabc/Cde/Ckl
Cabc/Cde/Ckl/H
Cabc/Cde/Ckl/I
Cabc/Cde/Ckl/L
Cabc/Cde/Ckl/S

Output 1:
%dir /usr/hw/Cabc/Cde
%dir /usr/hw/Cabc/Cde/Ckl
%attr(0444,root,root) /usr/hw/Cabc/Cde/Ckl/H
%attr(0444,root,root) /usr/hw/Cabc/Cde/Ckl/I
%attr(0444,root,root) /usr/hw/Cabc/Cde/Ckl/L
%attr(0544,root,root) /usr/hw/Cabc/Cde/Ckl/S
mkdir -p /usr/hw/Cabc/Cde/Ckl

Input 2:
Cabc/Cde
Cabc/Cde/Ckl
Cabc/Cde/Ckl/Olabel
Cabc/Cde/Ckl/Olabel/L
Cabc/Cde/Ckl/H
Cabc/Cde/Ckl/S
Cabc/Cde/Coo
Cabc/Cde/Coo/H
Cabc/Cde/Coo/I
Cabc/Cde/Coo/L
Cabc/Cde/Coo/S

Output 2:
%dir /usr/hw/Cabc/Cde
%dir /usr/hw/Cabc/Cde/Ckl
%dir /usr/hw/Cabc/Cde/Ckl/Olabel
%dir /usr/hw/Cabc/Cde/Coo
%attr(0444,root,root) /usr/hw/Cabc/Cde/Ckl/Olabel/L
%attr(0444,root,root) /usr/hw/Cabc/Cde/Ckl/H
%attr(0544,root,root) /usr/hw/Cabc/Cde/Ckl/S
%attr(0444,root,root) /usr/hw/Cabc/Cde/Coo/H
%attr(0444,root,root) /usr/hw/Cabc/Cde/Coo/I
%attr(0444,root,root) /usr/hw/Cabc/Cde/Coo/L
%attr(0544,root,root) /usr/hw/Cabc/Cde/Coo/S
mkdir -p /usr/hw/Cabc/Cde/Ckl/Olabel
mkdir -p /usr/hw/Cabc/Cde/Coo
 
Old 07-25-2008, 05:47 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
This wreaks of homework.
 
Old 07-25-2008, 06:02 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
For homework questions, you will need to provide what you have tried and what in particular is tripping you up. Don't expect us to do your homeword for you. That would be cheating. The only help at this stage is an RTFM answer. See the sed or awk manpages. You may have not even have read the material you should have to not have a clue how to procede.
 
Old 07-27-2008, 08:00 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
http://catb.org/~esr/faqs/smart-questions.html

PS Mr C, Freudian slip ?

wreak: http://dictionary.reference.com/search?q=wreak&x=0&y=0
reek: http://dictionary.reference.com/search?q=reek&x=0&y=0

 
Old 07-27-2008, 08:05 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Silly me - my fingers wreak havoc on, and no longer pay any attention to, my brain, and this reeks of senility.
 
Old 07-27-2008, 10:23 PM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,225

Rep: Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021Reputation: 2021
Yeah, I know the feeling. My spelling is usually v good, but my typing otoh ....
 
  


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
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
generate new string from a text file walterwaston Programming 2 10-08-2007 02:14 AM
in Pascal: how to exec a program, discard text output or send to text file Valkyrie_of_valhalla Programming 6 05-02-2007 09:50 AM
daunting task - read wml input, insert variables into URL, DL page, parse, write file jeffreybluml Programming 1 05-12-2005 06:31 AM
Can't rm file with Input/Output error drlaz Linux - General 0 02-23-2005 06:06 PM


All times are GMT -5. The time now is 03:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration