USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Extract information from a file csh script

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming
View previous topic :: View next topic  
Author Message
kamel
New Member


Joined: 11 Mar 2024
Posts: 3
Location: TT

PostPosted: Wed Mar 11, 2024 2:39 pm    Post subject: Extract information from a file csh script Reply with quote

Hi every body,

i have this file example :

TD1
TD2
TD3
.
.
.TDn

<DIE_1>
xxxxxx
<\DIE_1>
<TD1>
information 1
inormation n
<\TD1>
<TDq>
information
<\TD_q>
.
.
.
<DIE_m>
xxxxxx
<\DIE_m>
<TD3>
information 1
inormation n
<\TD3>
<TDP>
information
<\TD_p>


for example i can find TD3 in DIE_n and in DIE_p and this is true for each TD.

i want to print in each new file information of TDn and relative DIE where i find it, for example if TD3 is in DIE_n and DIE_p i will print this two files :

file1
<DIE_n>
xxxxxx
<\DIE_n>
<TD3>
information 1
inormation n
<\TD3>

file 2

<DIE_p>
xxxxxx
<\DIE_p>
<TD3>
information 1
inormation n
<\TD3>

please note that the information in TD3 of each DIE is not similar to the other.

who can use gawk for example to do that, it's hard for me.

many thanks


Back to top
View user's profile Send private message
platinummonkey
Advanced Member


Joined: 01 Mar 2024
Posts: 732
Location: Texas

PostPosted: Wed Mar 11, 2024 7:56 pm    Post subject: Reply with quote

please use code blocks.... (this will preserve formatting)

retry, this is quite unreadable and I'm not even sure what you are asking...



_________________
desktop - FreeBSD 7.2
laptop & server - Archlinux i686 kernel26 2.6.32.10-1
- TAMULinux-2.0.2-ALPHA
USB Boot - Archlinux i686 kernel26 2.6.32.10-1 USB boot
Back to top
View user's profile Send private message Visit poster's website AIM Address
kamel
New Member


Joined: 11 Mar 2024
Posts: 3
Location: TT

PostPosted: Thu Mar 12, 2024 10:44 am    Post subject: Reply with quote

Hi,

thanks for your reply, i will try to explain what i want:

i have this two file contain balise like html:

File A File B


<DIE_1>

information about DIE_1

<\DIE_1>

<TD_1>
information TD1

<\TD_1>

<TD_i>
information TDi

<\TD_i>

<DIE_p>

information about DIE_p

<\DIE_p>

<TD_m>
information TDm

<\TD_m>

<TD_q>
information TDq

<\TD_q>


FIle B1
<DIE_1>

information about DIE_1

<\DIE_1>

<TD_1>
information TD1

<\TD_1>

File B2

<DIE_1>

information about DIE_1

<\DIE_1>

<TD_i>
information TD1

<\TD_i>

and like that for all the DIE i will extract each TD and it's relative DIE :

if TD1 and TDm are in DIE_1 for example i will write two file DIE_1 contain each information of DIE and TD1 and TDi and this is true for all other DIE.

it will be like printing from special line but i don't find the loop to extract it.

many thanks


Back to top
View user's profile Send private message
platinummonkey
Advanced Member


Joined: 01 Mar 2024
Posts: 732
Location: Texas

PostPosted: Fri Mar 13, 2024 2:06 am    Post subject: Reply with quote

kamel wrote:

i have this two file contain balise like html:
File A File B
<DIE_1>
information about DIE_1
<\DIE_1>

......................

File B2
<DIE_1>
information about DIE_1
<\DIE_1>
<TD_i>
information TD1
<\TD_i>


dude... that whole thing is unreadable, no one has any idea wth that is..
use the CODE BLOCKS!!!


Example (remove the extra whitespace)
[ code ] file a [ /code ]
[ code ] file b [ /code ]

but from a very vague understanding you may look into awk or sed for this for a simple bash script.

p.s. if you can't word it in a manner that somebody can understand, then don't expect an answer. :/ Exclamation



_________________
desktop - FreeBSD 7.2
laptop & server - Archlinux i686 kernel26 2.6.32.10-1
- TAMULinux-2.0.2-ALPHA
USB Boot - Archlinux i686 kernel26 2.6.32.10-1 USB boot
Back to top
View user's profile Send private message Visit poster's website AIM Address
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Fri Mar 13, 2024 3:40 am    Post subject: Reply with quote

I'm going to take a stab in the dark here and give this a shot.

I am assuming your file is formatted something like this, with no extra tags:
Code:

<DIE_1>
    xxxx
</DIE_1>
    <TD_1>
        yyyy
    </TD_1>
    <TD_2>
        yyyy
    </TD_2>
...
    <TD_n>
        yyyy
    </TD_n>
<DIE_2>
    xxxx
</DIE_2>
    <TD_1>
        yyyy
    </TD_1>
    <TD_2>
        yyyy
    </TD_2>
...
    <TD_n>
        yyyy
    </TD_n>
<DIE_m>
    xxxx
</DIE_m>
    <TD_1>
        yyyy
    </TD_1>
    <TD_2>
        yyyy
    </TD_2>
...
    <TD_n>
        yyyy
    </TD_n>


Further I will assume that nowhere in your file do you use the character |

Code:
!/bin/bash
TEMP=/tmp/DIE.html
DIES="$(egrep [^/]DIE_[0-9]* base.html|tr -d '<>')"

tr "\n" "|" < $1|sed -e "s/<DIE_[0-9]*>/\n&/g" > ${TEMP}

for DIE in ${DIES}; do
    echo "Processing $DIE";
    grep "<$DIE>" ${TEMP}|tr '|' '\n' >$DIE.html
done


when executed:
Code:
$ ./DIES.sh DIES.html
Processing DIE_1
Processing DIE_2
Processing DIE_3
Processing DIE_4
Processing DIE_5
Processing DIE_6
Processing DIE_7
Processing DIE_8
Processing DIE_9
Processing DIE_10
Processing DIE_11
Processing DIE_12
Processing DIE_13
Processing DIE_14
Processing DIE_15
Processing DIE_16
Processing DIE_17
Processing DIE_18
Processing DIE_19
Processing DIE_20
$ ls -v
DIES.html   DIE_3.html  DIE_7.html   DIE_11.html  DIE_15.html  DIE_19.html
DIES.sh     DIE_4.html  DIE_8.html   DIE_12.html  DIE_16.html  DIE_20.html
DIE_1.html  DIE_5.html  DIE_9.html   DIE_13.html  DIE_17.html
DIE_2.html  DIE_6.html  DIE_10.html  DIE_14.html  DIE_18.html
$


and each DIE_n.html file contains:
Code:
<DIE_n>
    xxxx
</DIE_n>
   <TD_1>
      wwww
   </TD_1>
   <TD_2>
      xxxx
   </TD_2>
...
   <TD_m>
      zzzz
   </TD_m>



Hope this helps...



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
kamel
New Member


Joined: 11 Mar 2024
Posts: 3
Location: TT

PostPosted: Fri Mar 13, 2024 2:01 pm    Post subject: Reply with quote

thanks for your help Smile

it was not exactly what i want but it's helpful for me .


thanks again great forum


Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Mar 13, 2024 3:29 pm    Post subject: Reply with quote

Since Lord.DragonFly.of.Dawn gave it a try and at least gave you some ideas, can you take the code formatted version that he provided and explain where his suggestions helped, but also what else you are looking for? I looked at the first few attempts, but I cannot deduce from the description anything better than what Lord.DragonFly.of.Dawn has already suggested.

I think we'd like to help, but there may be a language barrier or some other issue because we are not fully understanding and appreciating what you are looking for. We would like to help if we can, and I do encourage you to keep refining your question. Doing so may actually help you figure out the answer, and at the very least, it will help you in the future when you formulate questions to do so in a manner that will assist those who want to help you out.

Given the example provided, you can certainly loop on TD, DIE, or whatever pattern you wish, so perhaps the example, even if not exactly what you want, will give you some ideas. I think the code provided ought to give you some tips on how to go about it. Does it at least help? If you need more help, try to explain what did help and also what you are having difficulty figuring out and we'll try to help some more.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Fri Mar 13, 2024 4:55 pm    Post subject: Reply with quote

How to ask questions the smart way
Quote:
When asking about code

Don't ask others to debug your broken code without giving a hint what sort of problem they should be searching for. Posting a few hundred lines of code, saying "it doesn't work", will get you ignored. Posting a dozen lines of code, saying "after line 7 I was expecting to see <x>, but <y> occurred instead" is much more likely to get you a response.

If you simply want a code review, say as much up front, and be sure to mention what areas you think might particularly need review and why.
Don't post homework questions

Hackers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
masinick
Linux Guru


Joined: 03 Apr 2024
Posts: 8615
Location: Concord, NH

PostPosted: Fri Mar 13, 2024 5:14 pm    Post subject: Reply with quote

Thanks for sharing this, DedannaRocks! It may be a good example for kamel and perhaps for others as well. ESR writes a classic document here, and his expertise is obvious.



_________________
Brian Masinick
Distros: SimplyMEPIS
sidux - no CAPS!, antiX, Debian
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 607
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Sat Mar 14, 2024 4:30 am    Post subject: Reply with quote

kamel wrote:
thanks for your help Smile

it was not exactly what i want but it's helpful for me .


thanks again great forum


well If it's not what you wanted I'm gonna need a better idea of your input file (remember to use the [ code ] bbtag so that I can see the formatting too) and a more exact description of what you want the output to be (describe or create an example of an output file.)

With more info I'm sure we can find the exact answer you need.



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
inactive
Sr. Member


Joined: 29 Aug 2024
Posts: 1207

PostPosted: Sun Mar 15, 2024 7:28 pm    Post subject: Reply with quote

The code tags you can find a button for in the post reply box. Just put whatever code you want to display, in between [ code ] and [ /code ] (although it will be without the spaces).



_________________
Mandriva 2024.1 PWP
Mandriva Cooker
ArtistX live
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Shell Scripting and Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse