Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Extract information from file

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #15  
Old Unix and Linux 05-15-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 July 2017, 6:19 PM EDT
Location: San Jose, CA, USA
Posts: 10,412
Thanks: 527
Thanked 3,638 Times in 3,104 Posts
Quote:
Originally Posted by vedanta View Post
Many thanks!
One problem I am seeing here is that awk also is reading the comment lines.
Is there a way to ignore all comment lines at the very beginning? Should I need to create a separate post for this? Thanks1
If you are having problems with comments in the shell scripts that are being fed into the script you specified in post #1 in this thread, you don't need to start a new thread; otherwise, you do.

Either way you need to explain what comments need to be removed and exactly how your awk script is supposed to determine what you consider to be a "comment line at the very beginning". The only comment shown in your sample input file(s) is:

Code:
#!/bin/ksh

and I don't see why removing that comment from your input files will make any difference in your results. If you don't supply representative sample input files corresponding to the data you want to process, you are wasting time for all of us.
Sponsored Links
    #16  
Old Unix and Linux 05-15-2017
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 27 July 2017, 2:26 PM EDT
Location: Simplicity
Posts: 3,642
Thanks: 285
Thanked 1,217 Times in 1,100 Posts
Quote:
Originally Posted by vedanta View Post
Many thanks!
One problem I am seeing here is that awk also is reading the comment lines.
Is there a way to ignore all comment lines at the very beginning? Should I need to create a separate post for this? Thanks.


I have used below as a solution

added !/^#/ eg,
/pfile/ && !/^#/ { ..
Most easy: at the beginning of the awk script put

Code:
/^#/ { next }

It will skip the following code whenever a #comment is met.
Sponsored Links
    #17  
Old Unix and Linux 05-15-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 July 2017, 6:19 PM EDT
Location: San Jose, CA, USA
Posts: 10,412
Thanks: 527
Thanked 3,638 Times in 3,104 Posts
Quote:
Originally Posted by MadeInGermany View Post
Most easy: at the beginning of the awk script put

Code:
/^#/ { next }

It will skip the following code whenever a #comment is met.
Note that it can't quite be at the beginning of the script... It has to come after:

Code:
awk ' NR==1 {
                        print "File      | Jobname |  node  | pfile               | metafile            | tname | priority | delay" # to be replaced by tab
                   }

or you won't get the desired heading line in your output file.
The Following User Says Thank You to Don Cragun For This Useful Post:
MadeInGermany (05-15-2017)
    #18  
Old Unix and Linux 05-15-2017
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 27 July 2017, 2:26 PM EDT
Location: Simplicity
Posts: 3,642
Thanks: 285
Thanked 1,217 Times in 1,100 Posts
Good point. The correct location is here

Code:
awk ' NR==1 { ...
  }
/^#/ { next }

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract information from file jiam912 Shell Programming and Scripting 11 11-12-2016 01:06 AM
Extract information from txt file edekP Shell Programming and Scripting 11 11-09-2016 12:32 PM
How to extract information from a file? the_simpsons Shell Programming and Scripting 9 05-20-2014 05:47 PM
Extract various information from a log file SilvesterJ Shell Programming and Scripting 4 09-27-2011 12:00 PM
extract and format information from a file sujoy101 Shell Programming and Scripting 12 04-16-2008 06:58 AM



All times are GMT -4. The time now is 08:55 PM.