Sponsored Content
Top Forums Shell Programming and Scripting awk command to display particular pattern Post 303016098 by sdosanjh on Thursday 19th of April 2018 03:13:54 PM
Old 04-19-2018
Quote:
Originally Posted by RudiC
This is difficult if not impossible, as you have spaces as field separators but also contained in desired output values. Do you see a chance to define fields and separators differently?

I tried below, but not able to remove one "(" Smilie

Code:
cat OutFile | grep GAP | awk -F'|' '{print $4}' |awk -F')' '{print $1}' |awk -F' ' '{print $3,$4,$5}'

Output

Code:
CL/U18 16P-NC (CL160U8
CL/N18 5.5P-NC (CL55S8
CL/Q18 9.5P-NC (CL95T8
CL/Q18 6.5P-NC (CL65T8
CL/M18 5.5P-NC (CL55R8

---------- Post updated at 11:13 AM ---------- Previous update was at 11:07 AM ----------

Quote:
Originally Posted by RudiC
Well, this might work, taking advantage of the data structure as shown:
Code:
awk  '
match ($0, /(GAP|DUP)[^)]*\)\)/)        {TMP1 = substr ($0, RSTART, RLENGTH-2)
                                         n = split (TMP1, T)
                                         TMP2 = sprintf ("%s %s\t%s", T[n-2], T[n-1], substr (T[n], 2))
                                         if (!CNT[TMP2]++) print TMP2
                                        }
' file
CL/U18 9P-NC	CL90U8
CL/X18 8.5P-NC	CL85W8



I am getting the below error
Code:
awk  '
>> match ($0, /(GAP|DUP)[^)]*\)\)/)        {TMP1 = substr ($0, RSTART, RLENGTH-2)
>>                                          n = split (TMP1, T)
>>                                          TMP2 = sprintf ("%s %s\t%s", T[n-2], T[n-1], substr (T[n], 2))
>>                                          if (!CNT[TMP2]++) print TMP2
>>                                         }
>> ' FILE
awk: syntax error near line 2
awk: bailing out near line 2

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to display only the pattern

Hi, I have a file with 500 Lines and I want to search for a pattern within this file which starts with sm_ and ends with ). However I just want to print the pattern only and not the entire line. How do I do it ? Thanks, p (5 Replies)
Discussion started by: yerics
5 Replies

2. UNIX for Dummies Questions & Answers

Awk help needed for display particular field alone for searching pattern

Hi, I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for, Note: The searching field varies its position... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

3. Shell Programming and Scripting

using command line arguments as columns for pattern matching using awk

Hi, I wish to use a column, as inputted by a user from command line, for pattern matching. awk file: { if($1 ~ /^8/) { print $0> "temp2.csv" } } something like this, but i want '$1' to be any column as selected by the user from command line. ... (1 Reply)
Discussion started by: invinclible0009
1 Replies

4. Shell Programming and Scripting

Want to grep for a pattern and display the content above that pattern

Hi, When we have a failure, sometimes we just step restart the job from the next step. Later when we open the log for analysis of the failure, it is becoming difficult to go to the failure part. For eg., if it is a 1000 line log, the failure may be at 500th line. so wat i want to do is, grep... (6 Replies)
Discussion started by: ajayakunuri
6 Replies

5. Shell Programming and Scripting

awk command to find particular pattern in file.

Hi I am using the following command to look for anything other than "0000" in a comma seperated file on 11th field. Note: I am looking for "0000" including the double quotes. nawk -F"," '$11!='"0000"'{print $11}' file This is showing incorrect result. Help is appreciated (2 Replies)
Discussion started by: pinnacle
2 Replies

6. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

7. Shell Programming and Scripting

a cut-command or special format pattern in awk

Hi i read data with awk, 01.07.2012 00:10 227.72 247.50 1.227 1.727 17.273 01.07.2012 00:20 237.12 221.19 2.108 2.548 17.367 01.07.2012 00:30 230.38 230.34 3.216 3.755 17.412 01.07.2012 00:40 243.18 242.91 4.662 5.172 17.328 01.07.2012 00:50 245.58 245.41 5.179 5.721 17.128... (3 Replies)
Discussion started by: IMPe
3 Replies

8. Shell Programming and Scripting

Sed/awk/perl command to replace pattern in multiple lines

Hi I know sed and awk has options to give range of line numbers, but I need to replace pattern in specific lines Something like sed -e '1s,14s,26s/pattern/new pattern/' file name Can somebody help me in this.... I am fine with see/awk/perl Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies

9. Shell Programming and Scripting

Display Additional Variable string in awk print command

Hi all, I have script to monitor and sum up the total memory use up for each individual process. proc=$1 svmon -P -O summary=basic,unit=MB|awk 'NR>4'|grep -w "${proc}" |awk '{sum+=$3} END {printf "\t" sum """\n";}' But I would like the script to be able to display as following ... (3 Replies)
Discussion started by: ckwan
3 Replies

10. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies
All times are GMT -4. The time now is 11:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy