awk how to print if the search pattern contains speace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk how to print if the search pattern contains speace
# 1  
Old 04-09-2008
awk how to print if the search pattern contains speace

the data file is as below:

HTML Code:
> cat master.cnf
/usr| location for usr|5
/src/ver1| version 1 |10
/src/ver2/log| ver 2 log |25
/src/sys/apps/log| Application log for sys|36
/src/sys/apps/conf| configuration location for app|45
/src/sys/apps/bin| binary location app|55my script is as below:
Code:
>desc='Application log for sys'
>echo $desc
Application log for sys
> awk -F '|' -v var=$desc '$0 ~ var{print $3}' master.cnf

Quote:
output is
input file "for"input file "sys"input file "$0 ~ var{print $3}"
/usr| location for usr|5
/src/ver1| version 1 |10
/src/ver2/log| ver 2 log |25
/src/sys/apps/log| Application log for sys|36
/src/sys/apps/conf| configuration location for app|45
/src/sys/apps/bin| binary location app|55Quote:
Quote:
I need to print field 3 separated by "|" and I want to use varibale to seach , the value of variable can contin the space char.
Please suggest me
# 2  
Old 04-09-2008
Double post or bumping up questions is not allowed, please read the:

https://www.unix.com/unix-dummies-que...om-forums.html

Continu here:

https://www.unix.com/shell-programmin...awk-slash.html


Thread closed.
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 to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

3. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

4. Shell Programming and Scripting

pattern search and print using sh

Hi All, Have a file contains multiple line with the following file.txt insert: akdkas job:ksdjf command: aldfasdf asdfsdfa asdfas.sh machine: asdfa need to grep for insert and machine and print only "akdkas,asdfa" cat file.txt | egrep "insert|machine" | awk -F: '{print $2}' output ... (5 Replies)
Discussion started by: uniqme
5 Replies

5. Shell Programming and Scripting

Print a Search Pattern after modification

Using either vim or awk or sed If I wish to to search for an unknown pattern - lets say 1B2495 or 1Q2345 so Search pattern : 1 and replace the 1 with 2 to print out : 2B2495 or 2Q2345 what are the possible commands. Struggling here - help would be appreciated. (5 Replies)
Discussion started by: dpooleco
5 Replies

6. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

7. Shell Programming and Scripting

Awk/Sed: Search Pattern from file and Print

Hi, I want to search for patterns (from a file) in a file and print the line matching the patterns and the line before it. I have to search for 100s of patterns from a file. Any help with AWK or Sed. Thanks! (2 Replies)
Discussion started by: saint2006
2 Replies

8. Shell Programming and Scripting

Search for Pattern and Print including Lines in between

Gurus, I have a big file that needs to be sorted out and I cant figure out what to do. The file name is as below: Name: xxxx yyyy nnnn Description: dfffgs sdgsgsf hsfhhs afgghhjdgj fjklllll gsfhfh Updated: jafgadsgg gsg Corrected: date today The file consists of line like these. ... (13 Replies)
Discussion started by: The One
13 Replies

9. UNIX for Dummies Questions & Answers

Print lines between the search pattern

hi, I have a file say x.txt containing xxx 123 bla bla ... you xxx dfk dbf ... me xxx ... ... keeps on.. i need to search for pattern in the line starting xxx in the file. If pattern matched, I need to fetch all the lines till i find next xxx. (17 Replies)
Discussion started by: prsshini
17 Replies

10. Shell Programming and Scripting

Print the line within the search pattern

Hi Guys, I had file as typedef struct { char TrailerType1; char TrailerTxt1; }Trailer; typedef struct { char PfigMoneyType; char PfigMoneyvalue; }PfigMoney; i need to print the lines within the search pattern. if i give the search pattern as... (3 Replies)
Discussion started by: manosubsulo
3 Replies
Login or Register to Ask a Question