Grep command to search pattern corresponding to input from user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep command to search pattern corresponding to input from user
# 8  
Old 04-03-2017
Hi,

My input file size is huge,but whatever i pasted here ,you can consider as input.

Output of above command is-
Code:
COS_12_TM_4
scan_out[5]
scan_out[9]

I want only - COS_12_TM_4 term
# 9  
Old 04-03-2017
Quote:
Originally Posted by Preeti Chandra
Hi,
My input file size is huge,but whatever i pasted here ,you can consider as input.
Output of above command is-
Code:
COS_12_TM_4
scan_out[5]
scan_out[9]

I want only - COS_12_TM_4 term
Hello Preeti Chandra,

Let's say following is Input_file.
Code:
cat Input_file
"COS_12_TM_2" [ ......
                                   ......
                                 "scan_out[51]" ] ;
"COS_12_TM_24" [ ......
                                   ......
                                 "scan_out[2]" ] ;
"COS_12_TM_4" [ ......
                                   ......
                                 "scan_out[5]" ] ;
"COS_12_TM_14" [ ......
                                   ......
                                 "scan_out[3]" ] ;

Then my code has give me the expected output mentioned by you as follows only.
Code:
awk '/ \[/{gsub(/\"/,"",$1);VAL=$1;} /scan_out\[5\]/{print VAL}' Input_file
COS_12_TM_4

Let me know if you have any queries or your Input_file looks different.

Thanks,
R. Singh
# 10  
Old 04-03-2017
Yes my input file is different .I try to point the area where scan_out[5] is present in my input file :

Code:
pattern MAIN ( "dft_jtag_sel", "dft_jtag_si", "dtm_global_rstb",  
               "DTM_VTRIM":I, "VDDA_1V8_DTM":I, "VDD_0V9":I, "VSS":I, 
               "scan_out[0]", "scan_out[10]", "scan_out[11]", "scan_out[12]", "scan_out[13]", "scan_out[14]", "scan_out[15]", "scan_out[1]", "scan_out[2]", "scan_out[3]", "scan_out[4]", "scan_out[5]", "scan_out[6]", "scan_out[7]", "scan_out[8]", "scan_out[9]", 
               "DTM_VTRIM":O, "VDDA_1V8_DTM":O, "VDD_0V9":O, "VSS":O )

Code:
"scan_out[15]" : output;      ## pinName = scan_out[15];  tf =  SO  ;  
    "scan_out[4]" : output;      ## pinName = scan_out[4];  tf =  SO  ; 
    "scan_out[5]" : output;      ## pinName = scan_out[5];  tf =  SO  ; 
    "scan_out[6]" : output;      ## pinName = scan_out[6];  tf =  SO  ;


Code:
 "scan_out[1]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ]; 
    "scan_out[2]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ]; 
    "scan_out[3]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ]; 
    "scan_out[4]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ]; 
    "scan_out[5]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ]; 
    "scan_out[6]" := output [ 0ns:X, 50.000000ns:Q, 100.000000ns:X ];

Code:
 "scan_out[3]" : output;      ## pinName = scan_out[3];  tf =  SO  ; 
    "scan_out[4]" : output;      ## pinName = scan_out[4];  tf =  SO  ; 
    "scan_out[5]" : output;      ## pinName = scan_out[5];  tf =  SO  ; 
    "scan_out[6]" : output;      ## pinName = scan_out[6];  tf =  SO  ; 
    "scan_out[7]" : output;      ## pinName = scan_out[7];  tf =  SO  ;

Code:
Last same which i posted earlier as input file.

Code:
COS_12_TM_4" [ 
         "dummy_COS_12_1_TM_4",
         "dummy_COS_12_2_TM_4",
         "dummy_COS_12_3_TM_4",
         "dummy_COS_12_4_TM_4",
         "dummy_COS_12_5_TM_4",
         "dummy_COS_12_6_TM_4",
         "dummy_COS_12_7_TM_4",
         "dummy_COS_12_8_TM_4",
         "dummy_COS_12_9_TM_4",
         "dummy_COS_12_10_TM_4",
         "dummy_COS_12_11_TM_4",
         "dummy_COS_12_12_TM_4",
         "dummy_COS_12_13_TM_4",
         "dummy_COS_12_14_TM_4",
         "dummy_COS_12_15_TM_4",
         "dummy_COS_12_16_TM_4",
         "dummy_COS_12_17_TM_4",
         "dummy_COS_12_18_TM_4",
         "dummy_COS_12_19_TM_4",
         "dummy_COS_12_20_TM_4",
         "dummy_COS_12_21_TM_4",
         "dummy_COS_12_22_TM_4",
         "dummy_COS_12_23_TM_4",
         "dummy_COS_12_24_TM_4",
         "dummy_COS_12_25_TM_4",
         "dummy_COS_12_26_TM_4",
         "dummy_COS_12_27_TM_4",
         "dummy_COS_12_28_TM_4",
         "dummy_COS_12_29_TM_4",
         "dummy_COS_12_30_TM_4",
         "dummy_COS_12_31_TM_4",
         "dummy_COS_12_32_TM_4",
         "dummy_COS_12_33_TM_4",
         "dummy_COS_12_34_TM_4",
         "dummy_COS_12_35_TM_4",
         "dummy_COS_12_36_TM_4",
         "dummy_COS_12_37_TM_4",
         "dummy_COS_12_38_TM_4",
         "dummy_COS_12_39_TM_4",
         "dummy_COS_12_40_TM_4",
         "scan_out[5]" ];

Lastly I want output from the last part of the file.

---------- Post updated at 04:58 AM ---------- Previous update was at 04:46 AM ----------

Can you explain me your command?
I will try at my end.
# 11  
Old 04-03-2017
Hello Preethi Chandra,

Your Input_file is not clear, please mention it more clearly. I have considered a Input_file which I posted in my previous post too, following is explanation of command.
Code:
awk '/ \[/                    #### Searching for a line which has " [" in it, so here I am using \[ to tell awk that take [ char to be searched not it's special meaning to be searched.
{gsub(/\"/,"",$1);        #### Now if that string found in a line then removing "(which they are there in the very first field) from first field.
VAL=$1;}                   #### creating a variable named VAL and storing $1's(fist field)'s value in it.
/scan_out\[5\]/           #### Now I am searching for string scan_out[5], here again I have escaped the characters [ and ] so that they should be taken as it is by awk.
{print VAL}                #### So if above string found in any line of Input_file then print the value of variable VAL which is nothing but your expected output.
' Input_file                 #### Mentioning the Input_file here too.

Also do not run above command it is only for explaining purposes, you should run my previous post command only. Let us know clearly what is your sample Input_file on single code tags then all the conditions by which you want to achieve the expected output too.

Thanks,
R. Singh
# 12  
Old 04-03-2017
Thank you very much for the explanation...

I am not getting the following command purpose-
Code:
{gsub(/\"/,"",$1);        #### Now if that string found in a line then removing "(which they are there in the very first field) from first field.

# 13  
Old 04-03-2017
Hello Preeti,

You could use THANKS button at left post corner for any useful post to anyone. So here is why I have used that command:
In your Input_file eg--> "COS_12_TM_2" first field is having chars " so you don't want them into your output so I had removed it, by using awk's global substitution keyword.

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

awk command to search based on 5 user input fields

Field1=”” Field2=”” Field3=”” Field4=”” Field5=”” USER INPUT UP TO 5 FIELDS awk -F , '{ if ( $3 == Field1 && $6 == Field2 && $8 == Field3 && $9 == Field4 && $10 == Field5) print $0 }' /tmp/rodney.outD INPUT FILE (Rodney.outD): ... (3 Replies)
Discussion started by: rmerrird
3 Replies

3. UNIX for Beginners Questions & Answers

Reducing input file size after pattern search

I have a very large file with millions of entries identified by @M. I am using the following script to "extract" entries based on specific strings/patterns: #!/bin/bash if ] then file=$1 else echo "Input_file passed as an argument $1 is NOT found." exit; fi MID=(NULL "string-1"... (10 Replies)
Discussion started by: Xterra
10 Replies

4. Shell Programming and Scripting

Search file pattern using grep command

I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing... (7 Replies)
Discussion started by: vinus
7 Replies

5. UNIX for Advanced & Expert Users

Pattern Search with grep

Hello, I have a bunch of zip files like SS_SAMPLE_101_123.zip SS_101_123.zip SS_SAMPLE_121_345.zip SS_SAMPLE_222_678.zip SS_123_890.zip SS_.zip The 'ls' should search and list the files such as SS_101_123.zip and SS_123_890.zip alone. Could you please guide me with this.... (5 Replies)
Discussion started by: tinufarid
5 Replies

6. Shell Programming and Scripting

Grep command is not search the complete pattern

I am facing a problem while using the grep command in shell script. Actually I have one file (PCF_STARHUB_20130625_1) which contain below records. SH_5.55916.00.00.100029_20130601_0001_NUC.csv.gz|438|3556691115 SH_5.55916.00.00.100029_20130601_0001_Summary.csv.gz|275|3919504621 ... (2 Replies)
Discussion started by: sumit.vedi1988
2 Replies

7. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

8. Shell Programming and Scripting

search for a pattern using grep

Hi I am facing the below problem. I have set of lines in which i have to search for only the line which matches with the pattren "/" only. input:- /*+ some text */ /*+ some text */ /* Remove rows from a table of survey results. */ /* Add a survey respondent's name and answers. */ /*... (7 Replies)
Discussion started by: manasa_vs
7 Replies

9. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

10. Shell Programming and Scripting

search pattern by grep

hai folks, i am vijay very new to this website. My query: Search patterns from root directory to all directories by using grep (3 Replies)
Discussion started by: vijaysabari
3 Replies
Login or Register to Ask a Question