Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching a quotation in the beginning of a field

Status
Not open for further replies.

AwkWeasel

Technical User
Sep 23, 2009
2
US
I need to print every record whose first field begins with a double quotation.

I began by trying to set my Record Separator as any word with a quotation in it. (since quotes appear later in the record also)

I can't seem to match the quotation in the $1.

The text looks like this:

Wards Room Source Site

"SMITH, JOHN L 01/30/02 373369 040618 EM




Here is what I have:

Begin { RS = "\" *[[:upper]]+ " }

$1 ~ /^\"/ { print $0 > "mfinal.txt" }



Thanks for looking
 
Since $1 is on the beginning of the line, you don't really need to examine the individual fields anyway, therefore no need to play with RS. As an aside, note that BEGIN should be in capitals.

Try:

Code:
awk '/^"/' inputfile > mfinal.txt

(Note, if you're working on Windows, you may have fun with quotes, so let us know...)

Annihilannic.
 
I am working with windows, so that may be why '/^"/' isn't matching anything.

I'll have to try a workaround.

Thank you for the input, though.
 
A simple workaround is to create a separate AWK script file, say myscript.awk, containing simply:

Code:
/^"/

Then the following should work:

Code:
awk -f myscript.awk inputfile > mfinal.txt

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top