If the fields in your file are sometimes single-quoted and are sometimes unquoted and you want to print the selected lines from your file as they appear in the input file (obviously wild assumptions since no sample of the desired output has been provided), everything that you are doing seems extremely complicated when the task seems so simple. The fact that your awk samples are using undefined shell variables and that your awk code changes with every post contributes to the confusion.
Does the following (based on your code in post #5 in this thread) come close to what you're trying to do:
Note that the patterns used for matching fields A and B (FAPat and FBPat, respectively) are anchored at both ends and allow 0 or 1 single quote at the beginning and end of the field being matched. With the sample data provided in post #1, this script produces the output:
As always, if you want to try this on a Solaris/SunOS system, change awk in the script to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Hi
I need to egrep patterns in a file and limit number of matches to print for each matched pattern.
-m10 option is not working out in my sun solaris 5.10
Please guide me the options to achieve.
if i do head -10 , i wont be getting all pattern match results as output since for a... (10 Replies)
I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Der colleagues,
4 days I am trying to solve my issue and no success..
Maybe you can give me a clue how to achieve what I need..
So I have two files.
file1 example:
1_column1.1 1_column2.1 aaa 1_column4.1
1_column1.2 1_column2.2 ttt 1_column4.2
1_column1.3 1_column2.3 ... (10 Replies)
I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file.
caw-enabled ... (3 Replies)
Good day,
I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after.
file1:
file2:
Output:
I can match a regex and print the line and line after
awk '{lines = $0} /Macrosiphum_rosae/ {print lines ; print lines } '
... (1 Reply)
Hi,
I am looking for a way to compare two text files and print the matches. For example;
File1.txt
89473036
78474384
48948408
95754748
47849030
File2.txt
47849030
46730356
16734947
78474384
36340047
Output: (11 Replies)
I am looking for equivalent of following awk command in perl
# awk '{ print NF ":" $0 } ' junk1
8:VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP DESCR
8:2 NIC6 cont 34 y n shal_orgrp /shal
8:4 NIC5 signa 52 n y shal_orgrp... (3 Replies)
Hi all,
I got several lines line this
a b c d e 1 e
a 1 c d e 3 f
a b c 1 e 8 h
a b c d e 1 w
a 1 c d e 2 w
a b c d e 1 t
a b c d e 7 4
How can I print the line if 1 is the field one before the last field?
Basicly this 2 field ?
a b c d e 1 e
a b c d e 1 t
The file I got is... (7 Replies)
If I have a file something like as shown below,
ARM*187878*hjhj
BAG*88778*jjjj
COD*7777*kkkk
BAG*87878*kjjhjk
DEF*65656*89989*khjkk
I need the line numbers to be added with a colon when it matches the string "BAG". Here in my case, I need something like
ARM*187878*hjhj... (4 Replies)