need help in string patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help in string patterns
# 1  
Old 08-18-2010
need help in string patterns

Hi,

i have following lines of code which is properly working.
Code:
 
CAT1="${InputFile}CAT_*0[0|1|2|3]?????"
CAT2="${InputFile}CAT_*0[4|5|6|7]?????"
 
CountRecords(){
integer i=1
while [[ $# -ne 0 ]]; do
print P$i `nawk 'END {print NR}' $1 ` >> ${OutputPath}result.txt &
i=i+1
shift
done
}
CountRecords "$CAT1" "$CAT2"

here CountRecords function accept "$CAT1" as 1st argument and "$CAT2" as second argument
what i want is to store "$CAT1" "$CAT2" in a variable and then apply to the function like

Code:
 
CAT="$CAT1 $CAT2"
CountRecords $CAT

When i tried this CountRecords accept both CAT1 and CAT2 as a single argument. i require the correct pattern so that it may take it again as two arguments

Plz help me
# 2  
Old 08-18-2010
Quote:
Originally Posted by malikshahid85
Code:
i=i+1

Is i being incremented for you?

Try
Code:
((i=i+1))

# 3  
Old 08-18-2010
Quote:
Originally Posted by KenJackson
Is i being incremented for you?

Try
Code:
((i=i+1))

thnks for reply

every thing is working fine. i just need to store $CAT1 and $CAT2 in a variable and pass this variable to the function but function should take it as two argument.
# 4  
Old 08-18-2010
Try
Code:
CAT="$CAT1 $CAT2"
eval CountRecords $CAT

# 5  
Old 08-19-2010
Quote:
Originally Posted by KenJackson
Try
Code:
CAT="$CAT1 $CAT2"
eval CountRecords $CAT

thnks it works but with some problems. it should give the following result.
Code:
 
P1 1467843
P2 6379402

but eval CountRecords $CAT gives both these results in the end but each and every file records too. like

Code:
 
.
.
.
P1533 14539
P1528 14771
P1520 13658
P1519 13604
P1 1467843
P2 6379402

i just require only last two results as my working script give. plz look into it.
# 6  
Old 08-19-2010
Quote:
Originally Posted by malikshahid85
thnks it works but with some problems. it should give the following result.
Code:
 
P1 1467843
P2 6379402

but eval CountRecords $CAT gives both these results in the end but each and every file records too. like

Code:
 
.
.
.
P1533 14539
P1528 14771
P1520 13658
P1519 13604
P1 1467843
P2 6379402

i just require only last two results as my working script give. plz look into it.
Please post your complete code with code tag.
And post the desired output.
# 7  
Old 08-19-2010
Quote:
Originally Posted by cola
Please post your complete code with code tag.
And post the desired output.
Code:
 
InputFile=/u02/atheerbi/SPOOL/IN/VOICE/test/CAT/
CAT1="${InputFile}CAT_*0[0|1|2|3]?????"
CAT2="${InputFile}CAT_*0[4|5|6|7]?????"
 
CAT="$CAT1 $CAT2"
 
CountRecords(){
integer i=1
while [[ $# -ne 0 ]]; do
print P$i `wc -l $1|tail -1|nawk '{print $1}'` >> ${OutputPath}result.txt &
i=i+1
shift
done
}

Following works and give me the result in result.txt file
Code:
 
CountRecords "$CAT1" "$CAT2"
P1 1467843
P2 6379402

but when i use eval it give me both result with count of all files indvidually.

Code:
 
eval CountRecords $CAT
.
.
so on
.
.
P1530 14478
P1533 14539
P1528 14771
P1520 13658
P1519 13604
P1 1467843
P2 6379402


Last edited by malikshahid85; 08-19-2010 at 08:15 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get string between 2 patterns

Hi all, I wish to get the string between u' and ' This is the test.txt file: PLAY *********************************** GATHERING FACTS ***************************** OK: TASK: **************************** changed: TASK: *************************** ok: => {"msg":... (11 Replies)
Discussion started by: celine
11 Replies

2. Shell Programming and Scripting

String search between patterns using sed

Hi, I am trying to find a way to get sed/awk/grep to help me find a string in a log file that exists between two datestamps and then print the preceding datestamp up to the next datestamp. Here is an example of my logfile: +++ 2013/03/28 17:01:37.085 SIGNALING HIGH ACTIVE Failure Response... (5 Replies)
Discussion started by: raytx
5 Replies

3. Shell Programming and Scripting

Fetching the string using different patterns

HI, Please help me with the following problem: I have an xml file with the following lines <NameValuePair> <name>SharedResources/JDBC/Admin/password</name> <value>rjmadmin</value> </NameValuePair> <NameValuePair> ... (4 Replies)
Discussion started by: tejastrikez
4 Replies

4. Shell Programming and Scripting

Getting a string from between two patterns

I need something to strip out some text from a string. I basically have a variable that will always be in the same pattern but will be a different length. Example below. I need to somehow extract the text between <Strat> and </Source> from example below. I can't load it into a file for audit... (5 Replies)
Discussion started by: atelford
5 Replies

5. Shell Programming and Scripting

parsing filename and grabbing specific string patterns

Hi guys...Wow I just composed a huge post and it got erased as I was logged out automatically Anyways I hope someone can help me out here. So the task I'm working on is like this I have a bunch of files that I care about sitting in a directory say $HOME/files Now my job is to go and loop... (6 Replies)
Discussion started by: rukasetsuna
6 Replies

6. UNIX for Dummies Questions & Answers

replace multiple patterns in a string/filename

This should be somewhat simple, but I need some help with this one. I have a bunch of files with tags on the end like so... Filename {tag1}.ext Filename2 {tag1} {tag2}.ext I want to hold in a variable just the filename with all the " {tag}" removed. The tag can be anything so I'm looking... (4 Replies)
Discussion started by: kerppz
4 Replies

7. Shell Programming and Scripting

need help in string patterns

Hi, i have a directory /u02.i have 2 files in it like abc1.gz abc2.gz i want to store file pattern in a variable like f1="abc?" i don't want to take .gz in variable rather i want .gz appended when i need to unzip the file like gunzip $f1 Can you please help me how to... (3 Replies)
Discussion started by: malikshahid85
3 Replies

8. Shell Programming and Scripting

To extract the string between two patterns

Sample input: Loading File System Networking in nature Closing the System now i need to extract the patterns between the words File and Closing: i.e. sample output: System Networking in Nature Thanks in advance !!!!!!!!!!!!!!!!! (6 Replies)
Discussion started by: aajan
6 Replies

9. UNIX for Dummies Questions & Answers

Counting patterns in a shell string

Hello, I am writing a shell script and I need to find a way to count the number of whitespaces in a string. Eg: NAME="Bob Hope" I am looking for a way to count the number of whitespaces in this string. So a command that would take this string and return 1. Or take "First Middle Last"... (3 Replies)
Discussion started by: kevin80
3 Replies
Login or Register to Ask a Question