LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-25-2010, 04:49 AM   #31
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

Based on example file you need to make one small change to Format.awk due to the use of tabs:
Code:
gsub(/^[/* ]*/,"")

# to

gsub(/^[/* \t]*/,"")
And then as far as I can see it seems to work swimmingly

You may also wish to remove the reference to column in flamingo_l.sh as I was using this for better formatting on STDOUT so I could see what I was getting.
 
Old 10-25-2010, 04:54 AM   #32
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Must be your copy of find is slightly different to mine. Try moving the '-type f' to the end.

And obviously remove the column command as you do not have it.
 
Old 10-25-2010, 05:28 AM   #33
flamingo_l
Member
 
Registered: Jul 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Yes, it is working now..

I also need file name in the output of the script, so only am adding the file name to the SAMPLE_FILE.txt in post no:18

Last edited by flamingo_l; 10-25-2010 at 05:32 AM.
 
Old 10-25-2010, 07:01 AM   #34
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well I am sure you want to do some of the work It is a fairly simple change ... let me know if you get stuck?

Obviously it will be in the Format.awk script file, and the hint is that the file name will only appear once in the DUMMY* file for all associated START/END combinations.
 
Old 10-25-2010, 08:24 AM   #35
flamingo_l
Member
 
Registered: Jul 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Lightbulb

hi Grail,

I have modified like below to get the file name:

Code:
#!/usr/bin/awk -f

BEGIN{
	FS="[ \t]*:[ \t]*"
	OFS="|"
	counter=0
}
{
	if ( $0 ~ "File name" )
	{
		arr[counter,$1]=$2
	}
}

/START|END/{
	if(/END/)counter++
	f=!f
	next
}

f{
    #gsub(/^[ /*]*/,"")
	gsub(/^[/* \t]*/,"")
	if(NF > 1)
		arr[counter,$1]=$2
	else
		arr[counter,last]=arr[counter,last]" "$0

	last=$1
}

END{
	print "File Name|Application Name|Release Number|Function Name|Changes"
	for(y=0;y<counter;y++)
		print arr[y,"File name"],arr[y,"Application Name"],arr[y,"Release Number"],arr[y,"Function Name"],arr[y,"Changes"]
}
But due to this, if the file contains more changes than the file name is appearing only in the first row.

Below is the result from your sample files:
Code:
File Name|Application Name|Release Number|Function Name|Changes
./t1/t2/file1.java|ZZZZZ|1.1|f_job_no_aktive()|Added logic in f_job_no_aktive()
|BBBBB|2.7|f_bobby_annno_aktiv()|Added logic in f_fluff_no_aktiv()
./t1/t2/t3/file2.java|XXXXX|1.0|f_job_no_aktiv()|Added logic in f_job_no_aktiv()
|JJJJJ|0.05|f()|Added a little bit of logic in f_job_no_aktiv()
The output which am expecting is

Code:
File Name|Application Name|Release Number|Function Name|Changes
./t1/t2/file1.java|ZZZZZ|1.1|f_job_no_aktive()|Added logic in f_job_no_aktive()
./t1/t2/file1.java|BBBBB|2.7|f_bobby_annno_aktiv()|Added logic in f_fluff_no_aktiv()
./t1/t2/t3/file2.java|XXXXX|1.0|f_job_no_aktiv()|Added logic in f_job_no_aktiv()
./t1/t2/t3/file2.java|JJJJJ|0.05|f()|Added a little bit of logic in f_job_no_aktiv()
 
Old 10-25-2010, 09:09 AM   #36
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well I commend you as you are on the right track. What you might need to think about is what the counter value is when you are hitting the File name?
 
Old 10-26-2010, 12:35 AM   #37
flamingo_l
Member
 
Registered: Jul 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Smile

Since in the sample file given by you has two comments, it will hit the file name only once.

During counter value 0 and 2(for the second file)...

The following code is working...

Code:
{
	if ( $0 ~ "File name" )
	{
		arr[counter,$1]=$2
		last_fn = $2
	}
	else
	{
		arr[counter,"File name"]=last_fn
	}
}
Please let me know if you any other way.
 
Old 10-26-2010, 01:13 AM   #38
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Code:
{
	if ( $0 ~ "File name" )
	{
		arr[counter,$1]=$2
		last_fn = $2
	}
	else
	{
		arr[counter,"File name"]=last_fn
	}
}

/START|END/{
	if(/END/)counter++
	f=!f
	next
}
Like I said ... on the right track and always good to get it working

Mine is only a variation on yours:
Code:
/File name/{ last_fn = $2 }


/START|END/{
        if(/START/)arr[counter,"File name"] = last_fn
	if(/END/)counter++
	f=!f
	next
}
 
1 members found this post helpful.
Old 10-26-2010, 01:29 AM   #39
flamingo_l
Member
 
Registered: Jul 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Yes correct ... Thank you Grail.

I was trying to understand the regextype in find command...

You have used posix-extended type.

What is the difference between a posix-egrep and posix-extended.?

Is there any reference material for the same.?

Also you have used exec command in the script.

Am trying to understand the following lines of code..

As per my research...

Code:
exec 3>&1 >$SAMPLE_FILE
All output from 3 is redirected to 1

Code:
exec >&3 3>&-
>&3 - means standard output is redirected to 3 and
3>&- means closing the descriptor 3.

So you are using this in the code to open up the sample_file,
write the contents and close it,.. Am i right.?

Also what is the use of this... as directly we can redirect the output to Sample file.

Last edited by flamingo_l; 10-26-2010 at 01:48 AM.
 
Old 10-26-2010, 02:48 AM   #40
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
What is the difference between a posix-egrep and posix-extended.?

Is there any reference material for the same.?
A quick google yielded: http://www.cs.vassar.edu/cgi-bin/inf...ression+syntax

Quote:
So you are using this in the code to open up the sample_file,
write the contents and close it,.. Am i right.?
Yes. See more information on exec here
Quote:
Also what is the use of this... as directly we can redirect the output to Sample file.
Yes you could but then you need to add your redirection to all lines that have to go to file. Admittedly in our example that is only 2 lines
but I find it looks cleaner. Also it has the added benefit of the reader seeing the file being opened and closed and should you choose
to add more lines later you can simply add them without remembering to redirect. Last bonus is that if you now wish to redirect a single line to STDOUT
you can point just that line at fd 3.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 05:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 04:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 04:13 AM
How to find files and copy the found files to the floppy in one command justmehere Linux - Newbie 11 05-04-2008 11:29 PM
problem with find command in script cojo Linux - Software 3 05-26-2004 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration