Create Summary file containg information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create Summary file containg information
# 1  
Old 10-20-2007
Create Summary file containg information

Folks,

I have multiple files in a folder containing some information (there is around 100 of them). What I would like to do would be able to import some of the information into a summary text file so that it will be easier to read a glance.

The name of the files all start with the naming convention S25E3N and contain simalar to the following info (the date and the number change):

3.0
206000
206000
22 march 2007

The way that I would I would like to put this into a summary file would be as follows (I only need to read the 3 and 4th line of the file):

File Count Reg Date
S25E3N41 206000 22 mar 2007
S25E3N17 0 20 oct 2007


Any ideas how I would go about doing this?
# 2  
Old 10-21-2007
You can do something like that with awk :
Code:
awk '
   function summary() {
      if (filename) print filename, number+0, date;
      filename = number = date = "";
   }
   BEGIN    { print "File", "Count", "Reg Date" }
   FILENAME != filename {
      summary();
      filename = FILENAME;
   }
   FNR == 3 { number = $0 }
   FNR == 4 { date   = $0 }
   END      { summary()   }

' S25E3N*

Jean-Pierre.
# 3  
Old 10-21-2007
if you have Python, here's an alternative:
Code:
import glob
os.chdir("/home/mydir_where_files_are")
o=open("output.txt","a")
o.write("File Count Reg Date\n")
for files in glob.glob("S25E3N*"):
    g=open(files).readlines()
    g[2]=g[2].strip() #strip newlines
    g[3]=g[3].strip()
    print >> o, files, ' '.join(g[2:4])
o.close()

usage : # python myscript.py
# 4  
Old 10-21-2007
Another one:
Code:
awk 'NR == 1{ printf m, "File" , "Count" , "Reg date" }
{ printf m, FILENAME, $3, $4 }
' RS= FS="\n" m="%-8s \t %s \t %s \n" S25E3N*

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 5  
Old 10-21-2007
awk

Hi,
This one should be ok.

code:

Code:
for fl in *
do
nawk -v f=$fl 'BEGIN{
tmp="S25E3N"f
}
{
if (NR==3 || NR==4)
	tmp=tmp"  "$0
}
END{
print tmp
}' $fl  >> test_tmp
done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create file and file content based existing information?

Hi Gurus, I am SQL developer and new unix user. I need to create some file and file content based on information in two files. I have one file contains basic information below file1 and another exception file file2. the rule is if "zone' and "cd" in file1 exists in file2, then file name is... (13 Replies)
Discussion started by: Torhong
13 Replies

2. UNIX for Beginners Questions & Answers

How to create a summary file of all files in a directory sorted in reverse alphabetical order.?

I have an interactive script which works terrific at processing a folder of unsorted files into new directories. I am wondering how I could modify my script so that( upon execution) it provides an additional labelled summary file on my desktop that lists all of the files in each directory that... (4 Replies)
Discussion started by: Braveheart
4 Replies

3. Shell Programming and Scripting

Using awk to create a summary of a structured file

I am trying to use awk to create a summary of a structured file. Here is what it looks like: (random text) H1 H2 H3 H4 44 78 99 30 31 -- 32 21 12 33 55 21 I'd like to be able to specify a column, say H2, and then have information about that column printed. ... (4 Replies)
Discussion started by: afulldevnull
4 Replies

4. Shell Programming and Scripting

Extract Lines Containg a Keyword

Hi , I have two files, say KEY_FILE and the MAIN_FILE. I am trying to read the KEY_FILE which has only one column and look for this column data in the MAIN_FILE to extract all the rows that have this key. I have written a script to do so, but somehow it is not returning all the rows ( It... (4 Replies)
Discussion started by: Sheel
4 Replies

5. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

6. Homework & Coursework Questions

2. Write a shell script that produces some summary information of the system at a particular moment

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: 3. The attempts at a solution (include all... (2 Replies)
Discussion started by: jsk319342
2 Replies

7. UNIX for Dummies Questions & Answers

pattern containg ' search and replace

Hi guys I'm new to this forum so please help me in this I have a file where i need to replace a pattern value=' ' with the pattern value='abc' and moreover that abc value must be passed from some variable say i assign name=abc and use name as the value to replace instead of the direct string... (10 Replies)
Discussion started by: sundarj
10 Replies

8. Shell Programming and Scripting

output nohup file containg the PID

Hi to everybody. Is it possible to nohup a process and redirect the output to a file containing the PID? E.g. if nohup filename > out.nohup associate the PID=8074 to filename, is it possible to call the output file something like out_8074.nohup instead of out.nohup? By this way it would... (0 Replies)
Discussion started by: plsrn
0 Replies
Login or Register to Ask a Question