06-17-2009
shell script to format file based on specific patterns
Please help me out and drag me out the deadlock I am stuck into:
I have a file. I want the statements under a if...then condition be listed in a separate file in the manner condition|statement.Following are the different input pattern and corresponding output parameters.any generic code to handle all these would be very very helpful.
Case:1 INPUT
------
if cond1 = true then
parm1=a
parm2=b
parm3=c
if cond2 = true then
parm3=d
parm4=e
end if
end if
OUTPUT
-------
cond1|parm1
cond1|parm2
cond1|parm3
cond2|parm3
cond2|parm4
Case:2 INPUT
------
if cond1 = true then
if cond2 = true then
parm1=a
parm2=b
parm3=c
parm3=d
parm4=e
end if
end if
OUTPUT
-------
cond1|cond2|parm1
cond1|cond2|parm2
cond1|cond2|parm3
cond1|cond2|parm3
cond1|cond2|parm4
Case:3 INPUT
------
if cond1 = true then
if cond2 = true then
end if
parm1=a
parm2=b
parm3=c
parm3=d
parm4=e
end if
OUTPUT
-------
cond1|parm1
cond1|parm2
cond1|parm3
cond1|parm3
cond1|parm4
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello All,
Here is the file which I want to edit. The script should look for DB2 and if found then delete all lines related to DB2 connection string. Is there way this can be done using script ?
DB1 =
(DESCRIPTION =
(SDU = 32768
(enable = broken)
(ADDRESS = (PROTOCOL =... (2 Replies)
Discussion started by: deepakc_in
2 Replies
2. Shell Programming and Scripting
Hi there,
I've an input file as follows:
*START
1001 a1
1002 a2
1003 a3
1004 a4
*END
*START
1001 b1
1002 b2
1004 b4
*END
*START
1001 c1
1004 c4
*END (6 Replies)
Discussion started by: kbirde
6 Replies
3. Shell Programming and Scripting
print 'test'
SETUSER 'dbo'
go
create proc abc
as
/Some code here/
go
SETUSER
go
print 'test1'
SETUSER 'dbo'
go
Create Procedure xyz
as
/some code here/
go
SETUSER
go
print 'test2'
SETUSER 'dbo' (2 Replies)
Discussion started by: mad_man12
2 Replies
4. Shell Programming and Scripting
Hi,
I have the following text file:
8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm
9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm
10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm
11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies
5. UNIX for Dummies Questions & Answers
Hi all,
1. I have a file that is getting continously refreshed (appended)
I want to grep all the strings containing substring of the type
abcdf123@aaa.xxx.yyy.zzz:portnumber:
where,
before @, any letters or numbers combination,
after @, IP address
then symbol :
then port... (4 Replies)
Discussion started by: kokoras
4 Replies
6. Shell Programming and Scripting
Hi All,
I am new to forum, I am looking to arrange a file in specific format but unable to get the formula to do it, already googled for the same, but didnt find the answer :(. hope to get help here :o:o:o:o:o
I have to files :
$ cat Dev_List2
0685
0686
0687
0688
0689
068A
068B
068C... (2 Replies)
Discussion started by: prasan_Aix
2 Replies
7. Shell Programming and Scripting
Hi All,
I have to pick particular segments from a file and I have prepared below shell script.But its not working and I am not able to find out whats the issue.could you guys pls help?
Sample file:
TS3*1451575*12*20151231*4*482.44
NM1*QC*1*CUTLER*BETTY
DTM*472*20150808... (4 Replies)
Discussion started by: Venkata Prasad
4 Replies
8. UNIX for Dummies Questions & Answers
Hello :)
I am in this situation:
Input: two tab-delimited files, `File1` and `File2`. `File2` (`$2`) has to be parsed by patterns found in `File1` (`$1`).
Expected output: tab-delimited file, `File3`. `File3` has to contain the same rows as `File2`, plus the corresponding value in... (5 Replies)
Discussion started by: dovah
5 Replies
9. UNIX for Beginners Questions & Answers
How do I use grep to select words that start with I or O, end in box, and contain at least one letter in between them?
the text file mailinfo.txt contains
Inbox
the Inbox
Is a match box
Doesn't match
INBOX
Outbox
Outbox1
InbOX
Ibox
I box
If the command works correctly it... (4 Replies)
Discussion started by: steezuschrist96
4 Replies
10. UNIX for Beginners Questions & Answers
I have
FILE 1 (This file has all master columns/headers)
A|B|C|D|E|F|G|H|STATUS
FILE 2
A|C|F|I|OFF_STATUS
3|4|5|4|Y
6|7|8|5|Y
Below command give me all headers of FILE 2 into array2.txt file
paste <(head -1 FILE2.txt | tr '|' '\n')>array2.txt
So I would like to compare... (2 Replies)
Discussion started by: jmadhams
2 Replies
TEST(1) General Commands Manual TEST(1)
NAME
test - condition command
SYNOPSIS
test expr
DESCRIPTION
test evaluates the expression expr, and if its value is true then returns zero exit status; otherwise, a non zero exit status is returned.
test returns a non zero exit if there are no arguments.
The following primitives are used to construct expr.
-r file true if the file exists and is readable.
-w file true if the file exists and is writable.
-f file true if the file exists and is not a directory.
-d file true if the file exists and is a directory.
-s file true if the file exists and has a size greater than zero.
-t [ fildes ]
true if the open file whose file descriptor number is fildes (1 by default) is associated with a terminal device.
-z s1 true if the length of string s1 is zero.
-n s1 true if the length of the string s1 is nonzero.
s1 = s2 true if the strings s1 and s2 are equal.
s1 != s2 true if the strings s1 and s2 are not equal.
s1 true if s1 is not the null string.
n1 -eq n2
true if the integers n1 and n2 are algebraically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place of
-eq.
These primaries may be combined with the following operators:
! unary negation operator
-a binary and operator
-o binary or operator
( expr )
parentheses for grouping.
-a has higher precedence than -o. Notice that all the operators and flags are separate arguments to test. Notice also that parentheses
are meaningful to the Shell and must be escaped.
SEE ALSO
sh(1), find(1)
TEST(1)