How and What should I read/study to can resolve this script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How and What should I read/study to can resolve this script?
# 1  
Old 05-18-2016
Linux How and What should I read/study to can resolve this script?

Hello everyone,

I am a newbie on the world Shell Script. I just can build some scripts basically with the command which I used on the terminal. With the part algorithmic I don't have problem, but some functionality I can't and didn't know how around the situation.

I have the file .txt with more a less 800 000 lines with this structure:

Code:
 . └── raiz  1 directory 
. ├── [ 16K]  ./raiz │   
├── [ 12K]  ./raiz/tgdf │   │ 
  ├── [6.0K]  ./raiz/tgdf/a_fazer │   │
   ├── [7.5K]  ./raiz/tgdf/a_fazer_5 │   │
   ├── [7.9M]  ./raiz/tgdf/analise_.pdf │   │   
├── [241K]  ./raiz/tgdf/141.pdf │   │  
 ├── [ 18M]  ./raiz/tgdf/Aulas.pdf ....

Which I need to do?
  1. Create an array with called "values";
  2. Read the file .txt and import the data on each line (all line) for to index the array called "values";
  3. The array called "values" will have another array, called "info_line";
  4. In the index, about array called "info_line", will be placed which was after last slash "/";
  5. The value this last array, "info_line", will receive which be between characters [...] - e.g. 6.0K;

Basically I new create a multidimensionally array.
The part which I don't know is "read the lines inside the file .txt" - collect exactly line by line. Collect the value which be after last slash "/".

I appreciate the guidance about how and what I should read an study for I can do this functionality. I have been reading about regular express, I think this is very useful to do this kind of jobs, am I correct?

I apologize about my level English, but if I can't explained the problem please tell me which I will try to explain the best I could. Thanks
# 2  
Old 05-18-2016
Not the easiest spec to understand. It might help to add the desired result or output, e.g. the multidimensional array and how it is populated.

And, it seems those thingies at line end are not pipe chars, but character graphics' vertical lines?

Last edited by RudiC; 05-18-2016 at 06:57 PM..
# 3  
Old 05-18-2016
Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.
# 4  
Old 05-18-2016
Hello,

RudiC, please tell me if this example explain and it serves you understand.

This is my file .txt:

Code:
.
└── raiz_

1 directory
.
├── [ 16K]  ./prfw_
│   ├── [ 12K]  ./prfw_/C0
│   │   ├── [ 98K]  ./prfw_/dfs/index.html
│   │   ├── [6.0K]  ./prfw_/dfs/a_asdf
│   │   ├── [7.5K]  ./prfw_/dfs/a_asfd_5
│   │   ├── [7.9M]  ./prfw_/dfs/asdfsaf.pdf
│   │   ├── [241K]  ./prfw_/dfs/asfasfsdc.pdf
│   │   ├── [ 18M]  ./prfw_/dfs/sdf dsf.pdf
│   │   ├── [ 116]  ./prfw_/dfs/backup.txt
.....continue until 180 000 lines

And I need this result, after run the algorithmic:

Code:
values=    [│   │   ├── [ 98K]  ./prfw_/dfs/index.html]
        [info_line=[index.html][98K]]
values=    [│   │   ├── [6.0K]  ./prfw_/dfs/a_asdf]
        [info_line=[a_asdf][6.0K]]

Don Cragun, this request don't will be the homework. I need this to management the files on the disk!

Thanks
# 5  
Old 05-18-2016
I'm still not quite sure what you request. But, mayhap this script (needs a recent bash; unfortunately you don't mention your OS nor shell version) comes close to what you want:
Code:
while read LINE
  do    IFS="][/" read -a ARR <<< $LINE
        echo $LINE
        echo ${ARR[1]} ${ARR[$((${#ARR[@]}-1))]}
  done <file
.
.
└── raiz_
└── raiz_

bash: ARR: bad array subscript

1 directory
1 directory
.
.
├── [ 16K] ./prfw_
16K prfw_
│ ├── [ 12K] ./prfw_/C0
12K C0
│ │ ├── [ 98K] ./prfw_/dfs/index.html
98K index.html
│ │ ├── [6.0K] ./prfw_/dfs/a_asdf
6.0K a_asdf
│ │ ├── [7.5K] ./prfw_/dfs/a_asfd_5
7.5K a_asfd_5
│ │ ├── [7.9M] ./prfw_/dfs/asdfsaf.pdf
7.9M asdfsaf.pdf
│ │ ├── [241K] ./prfw_/dfs/asfasfsdc.pdf
241K asfasfsdc.pdf
│ │ ├── [ 18M] ./prfw_/dfs/sdf dsf.pdf
18M sdf dsf.pdf
│ │ ├── [ 116] ./prfw_/dfs/backup.txt
116 backup.txt

As you can see, it has its weaknesses (e.g. for single item lines), and no error checking, but it may point you in the right direction...

Last edited by RudiC; 05-18-2016 at 07:12 PM.. Reason: typo
# 6  
Old 05-18-2016
Well, it's difficult to say what to read and study in this case. Regexes were not used at all in above. As it was done in pure shell, man bash is the document to read, and to exercise. Read these fora to learn how to use it (and other tools) and to pick up the tricks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Could not resolve ip through DNS

Dear all , Very recently our DNS server ip got changed. I have entered the DNS ip in /etc/resolv.conf ...but I could not resolv it for my ip address. Verified that , the IP is added in the DNS also. It is still working with the old DNS ip. Please let me know what could be... (11 Replies)
Discussion started by: jegaraman
11 Replies

2. Shell Programming and Scripting

Filter out IP addresses in domain resolve script

Hello everyone, I have written a one liner which looks in a configuration file for remote hosts to connect to. It then resolves them by first ping, and nslookup if it fails, then places the info in the hosts file. The whole thing works, seemingly, apart from one slight issue. I would like to... (0 Replies)
Discussion started by: haggismn
0 Replies

3. Shell Programming and Scripting

Resolve Environment Variable

I am tyring to resolve an environment variable that is part of a string I selected from our database. Simply put, I want cd to this folder before checking if a file exists. The variable $in_loc has the value '$PS_HOME/int/VSP' where $PS_HOME is the environment variable. I am using cd... (6 Replies)
Discussion started by: consult_jb
6 Replies

4. Shell Programming and Scripting

Please help to resolve the below script

Dear Members, Please help me to resolve below script. The script is used to send the attachment in the mail with all the details. However in one of the incidents, the attachment in the mail was blank. Now the client is after me to get it resolved ASAP. So prompt response would be highly... (2 Replies)
Discussion started by: SKO_TC
2 Replies

5. UNIX for Dummies Questions & Answers

Resolve IP to Hostname?

Good day, I would like to resolve IP's to Hostnames using Putty. I'm using Mandriva Linux 2008.0. Is this possible? Perhaps with nmap? (13 Replies)
Discussion started by: McGuywer
13 Replies

6. UNIX for Dummies Questions & Answers

Please resolve it

#!/bin/sh# 'clear'for i in $(seq -w 15 37)doecho $iecho The content in ZZ=`wget --dns-timeout=0.001 http://napdweb${i}.eao.abn-iad.ea.co.../test/test.jsp`echo $ZA="Connection timed out."echo The content in Aecho $Aexpr "$A" : '..\(...\)'echo $Adone Hi,Please see the above program. The above... (9 Replies)
Discussion started by: veerumahanthi41
9 Replies

7. Shell Programming and Scripting

please resolve the below problem

#!/bin/sh # 'clear' for i in $(seq -w 15 37) do echo $i echo The content in Z Z=`wget --dns-timeout=0.001 http://napdweb${i}.eao.abn-iad.ea.com:8000/webcore/test/test.jsp` echo $Z A="Connection timed out." echo The content in A echo $A expr "$A" : '..\(...\)' echo $A done ... (1 Reply)
Discussion started by: veerumahanthi41
1 Replies

8. Shell Programming and Scripting

Resolve a Variable

Hi I have a variable which is a path ie: UBERROR=/cobwrk/mchr/prodsup/ub/wrk/../error is there anyway I can get the output of an echo to read: #echo $UBERROR /cobwrk/mchr/prodsup/ub/error instead of #echo $UBERROR /cobwrk/mchr/prodsup/ub/wrk/../error Many thanks! (2 Replies)
Discussion started by: serm
2 Replies

9. UNIX for Dummies Questions & Answers

how do u resolve this????

Please help me on how to resolve: 1-unresponsive terminals 2-unresponsive applications 3-how to interrupt processe p.s unix/linux OS (1 Reply)
Discussion started by: zizu
1 Replies

10. IP Networking

Cannot Resolve Host Name

I am running LexMark MarkNetPro-3 print servers on my AIX network. All of the sudden, none of my printers will print anymore. I am getting an error message on the console: Unable to resolve host name. This message comes up everytime a user submits a print job. Any Ideas? (1 Reply)
Discussion started by: Docboyeee
1 Replies
Login or Register to Ask a Question