patterns between strings...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting patterns between strings...
# 1  
Old 07-12-2007
patterns between strings...

I have a small requirement


How to get patterns between string this way


Input..

05 ABC.
TAGTAG 10 AAA PIC 9
10 BBB PIC X
COMMET 10 CCC COMP PIC 9
05 DEF

I wanted to get all the variable between 05 ABC and next 05 level

out put should be

AAA
BBB
CCC
# 2  
Old 07-12-2007
For this specific case, what is your definition of a 'variable'?
# 3  
Old 07-12-2007
it a cobol code..

TAGTAG 10 AAA PIC 9
10 BBB PIC X
[ ]COMMET 10 CCC COMP PIC 9
05 DEF

1st six chars can be anything followed by some spaces

followed by some 2 digit numeric followed by a varible name... followed COMP or just a PIC
# 4  
Old 07-12-2007
Code:
sed -n '/^05 ABC/,/^05/p' input_file | sed '1d;$d' | \
while read mLine
do
  mVar=`echo $mLine | sed -e 's/.*[0-9]\{2\} \(.*\) .*/\1/' -e 's/ .*//'`
  echo "mVar = "$mVar
done

# 5  
Old 07-12-2007
thanks...

i was trying with awk '/^05 ABC/,/^05/' input_file

that didnt work

the sed worked ...

thanks
# 6  
Old 07-12-2007
Small extn to the Previous one

I have Some thing like this

SORT KEY FS-KEY1

###

SORT KEY FS-KEY2
FSKEY3

###

SORT KEY
FS-KEY4

###


Can we get the all the KEY Fields..

It Starts with SORT KEY and the KEY feilds can be in the same line or next line until ### comes
# 7  
Old 07-12-2007
Code:
mFound='N'
while read mLine
do
 mCnt=`echo $mLine | egrep -c 'SORT KEY'`
 if [ "${mCnt}" != "0" ]; then
   mFound='Y'
 fi
 if [ "${mLine}" = "###" ]; then
   mFound='N'
 fi
 if [ "${mFound}" = "Y" ]; then
   mOutLine=`echo ${mLine} | sed 's/SORT KEY//'`
   if [ "${mOutLine}" != "" ]; then
     echo "Key = "${mOutLine}
   fi
 fi
done < input_file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Match patterns between two files and extract certain range of strings

Hi, I need help to match patterns from between two different files and extract region of strings. inputfile1.fa >l-WR24-1:1 GCCGGCGTCGCGGTTGCTCGCGCTCTGGGCGCTGGCGGCTGTGGCTCTACCCGGCTCCGG GGCGGAGGGCGACGGCGGGTGGTGAGCGGCCCGGGAGGGGCCGGGCGGTGGGGTCACGTG... (4 Replies)
Discussion started by: bunny_merah19
4 Replies

2. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

3. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

4. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

Extract multiple occurance of strings between 2 patterns

I need to extract multiple occurance strings between 2 different patterns in given line. For e.g. in below as input ------------------------------------------------------------------------------------- mike(hussey) AND mike(donald) AND mike(ryan) AND mike(johnson)... (8 Replies)
Discussion started by: sameermohite
8 Replies

6. Shell Programming and Scripting

awk extract strings matching multiple patterns

Hi, I wasn't quite sure how to title this one! Here goes: I have some already partially parsed log files, which I now need to extract info from. Because of the way they are originally and the fact they have been partially processed already, I can't make any assumptions on the number of... (8 Replies)
Discussion started by: chrissycc
8 Replies

7. Shell Programming and Scripting

Concatenate text between patterns in individual strings

In any given file, wherever a certain data block exists I need to concatenate the values(text after each "=" sign) from that block. in that block. The block starts and ends with specific pattern, say BEGIN DS and END DS respectively. The block size may vary. A file will have multiple such blocks.... (12 Replies)
Discussion started by: Prev
12 Replies

8. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

9. Shell Programming and Scripting

script to edit strings based on patterns

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
Login or Register to Ask a Question