View previous topic :: View next topic |
Author |
Message |
kamel New Member
Joined: 11 Mar 2025 Posts: 3 Location: TT
|
Posted: Wed Mar 11, 2025 2:39 pm Post subject: Extract information from a file csh script |
|
|
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 |
|
platinummonkey Advanced Member

Joined: 01 Mar 2025 Posts: 732 Location: Texas
|
Posted: Wed Mar 11, 2025 7:56 pm Post subject: |
|
|
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 |
|
kamel New Member
Joined: 11 Mar 2025 Posts: 3 Location: TT
|
Posted: Thu Mar 12, 2025 10:44 am Post subject: |
|
|
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 |
|
platinummonkey Advanced Member

Joined: 01 Mar 2025 Posts: 732 Location: Texas
|
|
Back to top |
|
Lord.DragonFly.of.Dawn Advanced Member

Joined: 18 Jul 2025 Posts: 607 Location: South Portland, Maine, USA, Earth, Sol System
|
Posted: Fri Mar 13, 2025 3:40 am Post subject: |
|
|
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 |
|
kamel New Member
Joined: 11 Mar 2025 Posts: 3 Location: TT
|
|
Back to top |
|
masinick Linux Guru

Joined: 03 Apr 2025 Posts: 8615 Location: Concord, NH
|
Posted: Fri Mar 13, 2025 3:29 pm Post subject: |
|
|
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. |
|
Back to top |
|
inactive Sr. Member
Joined: 29 Aug 2025 Posts: 1207
|
Posted: Fri Mar 13, 2025 4:55 pm Post subject: |
|
|
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 2025.1 PWP
Mandriva Cooker
ArtistX live
|
|
Back to top |
|
masinick Linux Guru

Joined: 03 Apr 2025 Posts: 8615 Location: Concord, NH
|
Posted: Fri Mar 13, 2025 5:14 pm Post subject: |
|
|
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. |
|
Back to top |
|
Lord.DragonFly.of.Dawn Advanced Member

Joined: 18 Jul 2025 Posts: 607 Location: South Portland, Maine, USA, Earth, Sol System
|
|
Back to top |
|
inactive Sr. Member
Joined: 29 Aug 2025 Posts: 1207
|
Posted: Sun Mar 15, 2025 7:28 pm Post subject: |
|
|
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 2025.1 PWP
Mandriva Cooker
ArtistX live
|
|
Back to top |
|
|