Shell Scripting , need to search and print a line that contains a specific pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting , need to search and print a line that contains a specific pattern
# 8  
Old 09-07-2016
I am using the code provided above by vgersh99 , and it worked. Can someone please help me to use this command as case insensitive.

I mean it should ignore case sensitiveness.

Code:
PR="$(df -hTP | awk -vVAL="$my_var" '$1==VAL')"


Last edited by Don Cragun; 09-17-2016 at 05:16 AM.. Reason: Add CODE tags again.
# 9  
Old 09-07-2016
Code:
PR="$(df -hTP | awk -vVAL="$my_var" 'tolower($1)==tolower(VAL)')"

This User Gave Thanks to vgersh99 For This Post:
# 10  
Old 09-07-2016
Its working , Thank you so much Smilie
# 11  
Old 09-17-2016
Hi vgersh99 ,

Just need one more help , actually when i am running the below code on mutiple servers for the NFS filesystems , it gets hung , so is there any way we can add a timeout kind of thing to exit from the server where NFS is having issues and continue with next set of servers.
Code:
PR="(df -hTP | awk -vVAL="$my_var" 'tolower($1)==tolower(VAL)')"


Last edited by Don Cragun; 09-17-2016 at 05:21 AM.. Reason: Remove extraneous COLOR tags; add CODE tags again.
# 12  
Old 09-17-2016
Moderator's Comments:
Mod Comment This is getting old. Out of 9 posts by mohit_vardhani, 9 posts have had to be edited by a moderator to add CODE tags (and in some cases remove extraneous COLOR tags).

You have already seen the following at least twice before, but do not seem to have taken the time to read it and look at the tutorial. Please pay attention this time... Continued refusal to properly use CODE tags and to otherwise follow the forum rules you agreed to when you registered for this site may lead to you being banned from using this site.

To keep the forums high quality for all users, please take the time to format your posts correctly. Do not expect moderators and administrators to do this job for you.

Use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



And, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
# 13  
Old 09-17-2016
df can hang in statfs(). If you don't need the statfs result (size, used, free) then you better run the non-blocking
Code:
mount -v

and post-process it with awk.
# 14  
Old 09-17-2016
This will work , thank you and sorry for not using tags , now i got it.

One more thing , is there any way to timeout any command which is taking more time or hung in script due to any reason. I am using bash.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with print out record if first and next line follow specific pattern

Input file: pattern1 100 250 US pattern2 50 3050 UK pattern3 100 250 US pattern1 70 1050 UK pattern1 170 450 Mal pattern2 40 750 UK . . Desired Output file: pattern1 100 250 US pattern2 50 3050 UK pattern1 170 450 Mal pattern2... (3 Replies)
Discussion started by: cpp_beginner
3 Replies

2. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 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. Programming

Print specific pattern line in c++

Input file: @HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC +HWI-BRUNOP1_header_1 TNTTJTTTETceJSP__VRJea`_NfcefbWe Desired output file: >HWI-BRUNOP1_header_1 GACCAATAAGTGATGATTGAATCGCGAGTGCTCGGCAGATTGCGATAAAC >HWI-BRUNOP1_header_2... (10 Replies)
Discussion started by: cpp_beginner
10 Replies

5. Shell Programming and Scripting

Shell Scripting:Fetching content from each line with respect to pattern.

one.txt ONS.820.log:V 20Oct2010:GP ^ ^ ONS.123.log:V 21Oct2010:GP ^ ^ ONS.820.log:V 30Oct2010:GP ^ ^ want to make new file from existing one with addition. 20Oct2010 User KV001 has name tk003 with buffer- 338-1 21Oct2010 User KV003 has name tk002 with buffer- 338-2 30Oct2010 User KV002... (5 Replies)
Discussion started by: saluja.deepak
5 Replies

6. Shell Programming and Scripting

extract specific line if the search pattern is found

Hi, I need to extract <APPNUMBER> tag alone, if the <college> haas IIT Chennai value. college tag value will have spaces embedded. Those spaces should not be suppresses. My Source file <Record><sno>1</sno><empid>E0001</empid><name>Rejsh suderam</name><college>IIT ... (3 Replies)
Discussion started by: Sekar1
3 Replies

7. Shell Programming and Scripting

Search in specific position and print the whole line

I have two files abc.dat and sant.dat (Big file 60k rows) for every line's 1,4 of abc.dat need to seach if this is present on 28,4 of sant.dat every line. if its present the output needs to go to bde.dat Example: contents abc.dat aaaa bbbb cccc dddd contents sant.dat this is... (4 Replies)
Discussion started by: ssantoshss
4 Replies

8. Shell Programming and Scripting

Search word in a line and print earlier pattern match

Hi All, I have almost 1000+ files and I want to search specific pattern. Looking forwarded your input. Search for: word1.word2 (Which procedure contain this word, I need procedure name in output. Expected output: procedure test1 procedure test2 procedure test3 procedure test4 ... (7 Replies)
Discussion started by: susau_79
7 Replies

9. Shell Programming and Scripting

To print a specific line in Shell or awk.

Hi, I want to echo the 15th line from a file named as abc.txt, also i want to echo only the values in that line not the line number. Thanks in advance:) (4 Replies)
Discussion started by: tushar_tus
4 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