i have a file "Movie.ini" looking e.g. like follows
* MOVIE A
bla bla
MOVIE B
blubb blubb
MOVIE C
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
* MOVIE A
MOVIE B
MOVIE C
I have following problem, since I just know a bit ksh but not bsh:
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)
How can I check the first literal of an array-element whether it is a '*'?
Thanks a lot for any helpful answer
Please use CODE tags next time when displaying code, data or logs to enhance readability and to preserve formatting like indention etc., ty.
I want to read out ALL appearances of the string 'Movie' and check whether they ALL beginn with a '*'. So I think I need an array with a DYNAMIC number of fields since they number of 'Movie'-string varies.
But I think I need an array, because I want to check within a script if there is MOVIE without '' and if there is a MOVIE without '', a mail will be send. That part is already written and running, I just need a working if-clause.
grep ^MOVIE infile >/dev/null &&
printf '%s\n' "there is a MOVIE without *' |
mailx -s ... email@address
Notice that for some shells (like the Z-Shell) the ^ character is special and therefore you need to escape it.
Some implementations of grep support the -q/-s option to suppress the output, so if you use one of them, the command becomes:
grep -q ^MOVIE infile &&
printf '%s\n' "there is a MOVIE without *' |
mailx -s ... email@address
Thank you for that code, I will try it.
Is there any good but short online manual for bash-shell?
---------- Post updated at 06:17 AM ---------- Previous update was at 04:51 AM ----------
The code is unfortunately not enough, because the string MOVIE should ONLY occur with a '' as first literal. You did not check the case when it starts with an empty space for instance. Acctually the empty space is not a problem as long as a '' follows, so let me state my problem elseway:
As long as the number occurances of the string MOVIE and '' is the same, everything is right. So grepping the lines containing MOVIE is just the first step, in addition I hav to check whether ALL that lines have ''
Hi,
I need no array, but the postings so far do not solve my problem. Remember I need a file containing ALL lines from MySampleInfile containing the string 'MOVIE' but NOT beginning with '*'
I proceed now as follows, not needing an array anymore
grep MOVIE MySampleInfile >Output1
by this I have ALL lines containing Movie, no matter if they start with '*' or not
In a second step I want to filter all lines beginning with a space or another literal than ''. So may statement has to be "Filter ALL lines NOT beginning with '' "
grep not ^* Output1 >Output2
That does not work of course, but how can I write a NOT-Statement for the first literal?
grep MOVIE $vINIFILE >>tmp_filter_1
grep ^[a-zA-Z0-9' '] tmp_filter_1 >>tmp_filter_2
So all lines NOT beginning with '*' are written into the file tmp_filter_2.
If the file tmp_filter_2 is NOT empty, I know for sure there is something wrong and I send my message.