07-31-2009
Bash: Zeilen aus Datei mit cat und grep in dynamisches Array schreiben
Hallo,
ich habe eine Datei "Kino.ini" die z.B. wie folgt aussieht
* KINOFILM A
bla bla
KINOFILM B
blubb blubb
KINOFILM C
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
* KINOFILM A
KINOFILM B
KINOFILM C
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
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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/mycat.sh -h option
arguments=$#
if ] #in case of standard input
then
while ]
do
read input... (4 Replies)
Discussion started by: sanchopansa
4 Replies
2. Shell Programming and Scripting
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
3. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Solaris
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
7. Shell Programming and Scripting
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
8. Shell Programming and Scripting
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
9. Shell Programming and Scripting
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
10. Shell Programming and Scripting
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
ZGREP(1) General Commands Manual ZGREP(1)
NAME
zgrep - search possibly compressed files for a regular expression
SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename...
DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code:
(-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the
standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep.
If the GREP environment variable is set, zgrep uses it as the grep program to be invoked.
EXIT CODE
2 - An option that is not supported was specified.
AUTHOR
Charles Levert (charles@comm.polymtl.ca)
SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1)
ZGREP(1)