Bash: Zeilen aus Datei mit cat und grep in dynamisches Array schreiben

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: Zeilen aus Datei mit cat und grep in dynamisches Array schreiben
# 1  
Old 07-31-2009
Bash: Zeilen aus Datei mit cat und grep in dynamisches Array schreiben


ich habe eine Datei "Kino.ini" die z.B. wie folgt aussieht

bla bla
blubb blubb

Ich möchte nun die Datei "Kino.ini" per cat und grep auslesen und testen ob der String KINOFILM nur mit einem '*' am Anfang vorkommt. In dieser Beispieldatei gibt es KINOFILM gleich zweimal OHNE '*' als erstes Zeichen einer Zeile. Die Bedingung sollte greifen und ich springe in die folgende Anweisung XY:

Ich würde nun mit
"cat Kino.ini| grep KINOFILM >> tmp_KINOFILM"
alle Zeilen mit KINOFILM in eine Zwischendatei speichern


Ich habe nun aber folgende Probleme, da ich nur ein Bißchen ksh kann, aber nicht bsh:

1. Wie kann ich die Zeilen der Datei "tmp_KINOFILM" in ein VARIABEL langes / dynamisch allokiertes Array schreiben? (Es können mal 3, mal 5 oder 100 KINOFILME sein)
2. Wie kann ich das erste Zeichen eines Arrayelementes prüfen, ob es ein '*' ist?

Jetzt schon einmal vielen Dank für jede hilfreiche Antwort
# 2  
Old 07-31-2009

Per our forum rules, all posts must be in English.

We do provide translation services for posts from English to a number of languages as a benefit to users. However, posts must be in English.

Please repost in English.

Thank you for your cooperation.

The UNIX and Linux Forums.
# 3  
Old 07-31-2009
Bash: Reading out rows of a file into a dynamic array and check first literal


i have a file "Movie.ini" looking e.g. like follows

bla bla
blubb blubb

I'd like to read the file "Movie.ini" with cat and grep and check whether it includes the string MOVIE only with a '*' at the beginnig.

By doing
"cat Movie.ini| grep MOVIE >> tmp_MOVIE "
all rows containing MOVIE should be saved in a tempfile


I have following problem, since I just know a bit ksh but not bsh:

1. How can I read out the rows of the file "tmp_MOVIE" in a VARIABLE long / dynamic allocated array? (Since there is NOT a fix number of rows containing the string MOVIE - it can be 3, 5 or e.g. 20)
2. How can I check the first literal of an array-element whether it is a '*'?

Thanks a lot for any helpful answer
# 4  
Old 07-31-2009
Semi double post - continue here:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

2. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

3. Shell Programming and Scripting

How do I cat into an array or is it not possible?

Hi, Normally, I would do cat /etc/oratab | grep -v "^#" | grep -v "^*" > /tmp/oratab.00 while read line do echo $line done < /tmp/oratab.00I want to know whether it is possible to use an array instead of re-directing it to file? As a test, I did something like below: #!/bin/ksh ... (6 Replies)
Discussion started by: newbie_01
6 Replies

4. Shell Programming and Scripting

Bash Scripting - How to grep a file into an array

I have figured out how to grep the file like this: echo `grep $(date +'%Y-%m-%d') Cos-01.csv | cut -d',' -f1` The above line does echo the correct information from the lines in which my search criteria is found. Now I am trying to get that information (Yes, just one column of every line) into... (6 Replies)
Discussion started by: TwelveDays
6 Replies

5. Solaris

rdesktop zugriff auf W2K8R2 Farm mit NLB und Session Broke - server sent an unexpectedly long string

Hallo :-) Ich habe da ein Problem beim Zugriff von Solaris mittels rdesktop auf eine TS Farm unter W2K8R2 mit NLB und Session Broker. Ich bekomme folgende Fehlermeldung: user@sunray2xxx /h/user/Desktop 150 > rdesktop terminalserver WARNING: Remote desktop does not support colour... (1 Reply)
Discussion started by: chrischi1978
1 Replies

6. Shell Programming and Scripting

Suchen und Ersetzen mit AWK

Hallo, ich habe mir mit meinen dürftigen Programmierkenntnissen ein Script zusammengebastelt über das ich in einem bestimmten Odner mit AWK alle Dateien eines Verzeichnis durchsuche und bestimmte Bezeichungen aller Dateien ändern kann. Es funktioniert auch soweit, nur hätte ich gerne auch die... (1 Reply)
Discussion started by: ruffi
1 Replies

7. Shell Programming and Scripting

mit Sed Text aus Datei nur nach dem ersten Treffer einfügen

Hello, I'm new in Shell scripting but i should write a script, which inserts the license header out of a txt-File into the files in our Projekt. For the Java classes it runs without Problems but for XML files not. At xml-files i have to put the license Header after the xml-Header (?xml... (2 Replies)
Discussion started by: PhoenixONE
2 Replies

8. Shell Programming and Scripting

cat -n and grep

I am not sure if using cat -n is the most efficient way to split a file into multiple files, one file per line in the source file. I thought using cat -n would make it easy to process the file because it produces an output that numbers each line that I could then grep for with the regex "^ *$i".... (3 Replies)
Discussion started by: kapu
3 Replies

9. Shell Programming and Scripting

Read files, lines into array, cat vs open

Hi Everyone, I have a file: a.txt a,b,c,d,6,6,6 1,2,3,d,6,6,6 4,5,6,6,6,6,6 #!/usr/bin/perl use warnings; use strict; my @array = (); ### Load file into array for my $i (split '\n', `cat /tmp/a.txt`) { push @array, ; } It works. But my a.txt have 1million lines, and... (2 Replies)
Discussion started by: jimmy_y
2 Replies

10. Shell Programming and Scripting

need help with my implementation of cat in bash

Hello, A few days ago I created my amateur version of the cat function in bash. Here is what I've done: #!/bin/bash #This is mycat. Similar to cat. #For detailed information use path/to/ -h option arguments=$# if ] #in case of standard input then while ] do read input... (4 Replies)
Discussion started by: sanchopansa
4 Replies
Login or Register to Ask a Question