Pattern matching New to Sed & Awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Pattern matching New to Sed & Awk
# 1  
Old 04-16-2009
Bug Pattern matching New to Sed & Awk

Hello,
Despite reading the Pattern Matching chapter in the O'Reilly Sed & Awk book several times and
looking at numerous examples, I cannot seem to get any kind of conditional script to work in my awk scripts!
I am able to do the basic awk and grep script to capture the data but when I do with OR (||) or AND (&&) I keep getting error.
So unable to get selective records.I am pretty new to Unix and can do very basic commands only. Any help would be appreciated.
Thanks very much.

Here is an sample data file I have :

<3icmt001>
Here is a list of application related files which have been found on the remote SMB shares :
+ Software :
\cmdb_web.zip
</3icmt001>
<3idbi002>
- SQLDATA - (readable,writable)
+ Content of this share :
..
DCDB
DTSDB
P8DB
- eventlogs$
+ Content of this share :
..
DCDB
DTSDB
P8DB
- Services
+ Content of this share :
..
DCDB
DTSDB
P8DB

</3idbi002>

I need to get the following output file in order to load the data into my Oracle D/B using SQLLDR:

3icmt001,application,Software,cmdb_web.zip
Field 1 = Computer name
Field 2 = file type
Field 3 = share name
Field 4 = store filename

Note: (Conditions)

1. The next record <3idbi002> will not be selected because it doesn't have file type of "application" or "files" or "others".(Like the sentence
(Here is a list of application related files which have been found on the remote SMB shares Smilie
2. There could be multiple store filenames(\cmdb_web.zip) in which case the new row should have the same computer name,file type,share name
and the new store filename.(eg: If the new store filename are : \P8CE-3.5.2-014.exe and \mycount.bat then the new rows will be
3icmt001,application,Software,P8CE-3.5.2-014.exe
3icmt001,application,Software,mycount.bat
3. If there is no file type of "application" or "files" or "others". then cannot select the Computer name or share name. So no new row is created.
========================================================

Here is an example of how I was trying to pick the right number of rows for share name
awk '{ if ($1 ~ /<.*>/ && $1 ~ /Here is a list/ && $1 ~ /^\+ */ ) print $2 }' open_windows_shares1.txt
awk: syntax error near line 1
awk: illegal statement near line 1

If I do a grep I can pick up everything.
grep '\+.*:' open_windows_shares1.txt
+ PECLient353 :
+ TEMP :
+ Software :
+ Content of this share :
+ Content of this share :
+ Content of this share :
+ temp :
+ Siteminder :
+ temp :
+ AscentSV :
+ AscentSV :
+ AscentSV :
+ AscentSV :
+ Reports :
+ Models :
+ TSO Downloads :
+ Temp :
+ Content of this share :

I should not pick up "+ Content of this share :" since it doesn't have the file type.

Thanks very much
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

2. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

3. Shell Programming and Scripting

awk pattern matching in place of sed

I have written a script to parse data from some files on a Solaris 10 system and send the output to a CSV formatted file. The code snipped i am using to pull the data is as follows.... src_line=$(sed -n "/^search_pattern$/{=;}" $file) for i in $src_line do start_line1=$(( i + 9 )) nawk -v... (4 Replies)
Discussion started by: electricheadx
4 Replies

4. Shell Programming and Scripting

Pattern Matching & replacing of content in file1 with file2

I have file 1 & file 2 with content mentioned below. I want to get the output as shown in file3. Requirement: check the content of column 1 & column 2, if value of column 1 in file1 matches with first column of file2 then remaining columns(2&3) of file2 should get replaced, also if value of... (4 Replies)
Discussion started by: siramitsharma
4 Replies

5. Shell Programming and Scripting

Pattern matching & storing result in variable

Hi! i'm trying to parse textfiles against a pattern and storing the result in a variable. The strings i want to get are embraced by and can occur several times in one line, so e.g. some text anything else endwhat i have so far: #!/bin/bash for f in $* do exec 3<&0 exec 0<$f ... (2 Replies)
Discussion started by: thoni
2 Replies

6. Shell Programming and Scripting

AWK - Pattern Matching & Replacing - Performance

Experts, I am a beginner to Unix Shell Scripting We have source as a flat file which contains CTRL+F character as the delimiter. We need to count the number of records in the file (CTRL+F) to perform file validation Following command being used: awk '{cnt+=gsub(//,"&")}END {print cnt}'... (4 Replies)
Discussion started by: srivijay81
4 Replies

7. UNIX for Dummies Questions & Answers

Matching pattern script (sed or awk?)

Hi Guys, I am new to the forum and to scripting so bear with me. Thanks, Gary. I have 3 files - file1, file2, file3 I am trying to come up with a script that will check the output of these files and if the 1st nine fields are matched in all 3 files, echo "The following string had been... (2 Replies)
Discussion started by: gazza-o
2 Replies

8. Shell Programming and Scripting

SED pattern matching help

Hello All, I have the following lines in a file <address location="test" ConnectionName="test" /> I want to replace the above lines by <address location="test123" /> I am usind SED and not able to remove the new line characters between the two lines. Can anyone please help... (4 Replies)
Discussion started by: ramk
4 Replies

9. Shell Programming and Scripting

sed - matching pattern one but not pattern two

All, I have the following file: -------------------------------------- # # /etc/pam.d/common-password - password-related modules common to all services # # This file is included from other service-specific PAM config files, # and should contain a list of modules that define the services... (2 Replies)
Discussion started by: RobertBerrie
2 Replies

10. Shell Programming and Scripting

matching a pattern in a file & prefixing a word

Hi, In my shell script i have to match a patten in a file , if found i have to prefix the entair line by a "word" eg. pattern = "aaa" prefix= #123 file: bbbb xxx zzzz aaaa qqqq kkkk outPut file: bbbb xxx ... (5 Replies)
Discussion started by: shivarajM
5 Replies
Login or Register to Ask a Question