AWK specific output filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK specific output filename
# 8  
Old 08-10-2012
Awesome! I just had to make one change to get it to work. I changed FNR==1 to NR==1. So I didn't get the header every other line. fAWKing sweet!
# 9  
Old 08-10-2012
Quote:
Originally Posted by LMSteed
Awesome! I just had to make one change to get it to work. I changed FNR==1 to NR==1. So I didn't get the header every other line. fAWKing sweet!
OK. I completely misunderstood what you were trying to do. Smilie I thought line 1 of EACH input file specified the filename where converted output for that input file was supposed to be written and I assumed you wanted a header in each output file. If you change the FNR==1 to NR==1, then the output file will be determined by the first line of the first file you process and line one in every other input file will be completely ignored (and in this case you don't need to worry about closing output files). Even though your sample input only showed two lines, I'm also surprised that you only have one line of data in each file. That is why my original code had:
Code:
FNR==1 { do stuff for line one in each file;next}
    { do stuff for every line except line one in each file }

Also in your orginal problem statement, your input had five fields; now it has eight. If you have a lot of fields to process at some point you want want to change:
Code:
    {print $1,$2,...,$NF >> outputfile}

to:
Code:
    {$1=$1;print >> outputfile}

I'm glad you got something that is working for you.
# 10  
Old 08-10-2012
More details.. line one of my files contains the same thing.. which represents the filename I'd like to use as my output file. The second line contains statistics on a single channel of data. All of this is because I can't get the software vendor to export the statistics nicely. So the process is to open a file, read the first line, set it as the output variable name, and then process all the files for data on their second line sending all of this data to the same output file. This was my easiest option.. The only other option I have is to process a file that contains all of the data streams in column form. Column 1 would be abscissa data, Column 2 oridinate for channel 2, then ordinate for channel 3, so on and so on.. but when talking time domain data, these files are too large to 1) output and 2) process. When talking frequency domain data, I think it would be easy but I would most likely switch over to Matlab. I wrote an AWK script awhile ago for interactively switching RBE2s to RBE3s in NEdit and found that it was a great utility. Thanks for all your help.. one of these days I will understand the {}. I would like to find a good way to generate an awk error file, but based on all my recent google searches I think I can find a way to do it. Thanks again!
# 11  
Old 08-10-2012
Quote:
Originally Posted by LMSteed
More details.. line one of my files contains the same thing.. which represents the filename I'd like to use as my output file. The second line contains statistics on a single channel of data. All of this is because I can't get the software vendor to export the statistics nicely. So the process is to open a file, read the first line, set it as the output variable name, and then process all the files for data on their second line sending all of this data to the same output file. This was my easiest option.. The only other option I have is to process a file that contains all of the data streams in column form. Column 1 would be abscissa data, Column 2 oridinate for channel 2, then ordinate for channel 3, so on and so on.. but when talking time domain data, these files are too large to 1) output and 2) process. When talking frequency domain data, I think it would be easy but I would most likely switch over to Matlab. I wrote an AWK script awhile ago for interactively switching RBE2s to RBE3s in NEdit and found that it was a great utility. Thanks for all your help.. one of these days I will understand the {}. I would like to find a good way to generate an awk error file, but based on all my recent google searches I think I can find a way to do it. Thanks again!
You're welcome.

Note that if you had given us all of this information in your original post you would have had a working solution hours earlier and saved some of us a lot of extra work. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

awk to output match and mismatch with count using specific fields

In the below awk I am trying output to one file those lines that match between $2,$3,$4 of file1 and file2 with the count in (). I am also trying to output those lines that are missing between $2,$3,$4 of file1 and file2 with the count of in () each. Both input files are tab-delimited, but the... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. UNIX for Dummies Questions & Answers

awk : dynamic output flatfile filename

Hello, I'm using the awk command to insert empty columns on a tab delimited flatfile - which works fine - => But I'm not able to manage dynamicaly the filename of the awk output based on the source flatfile filename I have 3 source flatfile: flatfile_Jan-2016.csv flatfile_Feb-2016.csv... (3 Replies)
Discussion started by: Tipiak
3 Replies

4. Shell Programming and Scripting

awk to place specific contents filename within text file

I am trying to use awk to place the contens of a filename in $1 and $2 followed by the data in the text file. Basically, put the filename within the text file. There are over 1000 files in the directory and as of now each file is saved with a unique name but it is not within the file. Thank you... (10 Replies)
Discussion started by: cmccabe
10 Replies

5. Shell Programming and Scripting

awk to output specific matches in file

Using the attached file, the below awk command results in the output below: I can not seem to produce the desired results and need some expert help. Thank you :). awk -F'' ' { id += $4 value += $5 occur++ } END{ printf "%-8s%8s%8s%8s\n", "Gene", "Targets", "Average Depth", "Average... (3 Replies)
Discussion started by: cmccabe
3 Replies

6. UNIX for Advanced & Expert Users

Problem piping find output to awk, 1st line filename is truncated, other lines are fine.

Today I needed to take a look through a load of large backup files, so I wrote the following line to find them, order them by size, and print the file sizes in GB along with the filename. What happened was odd, the output was all as expected except for the first output line which had the filename... (4 Replies)
Discussion started by: gencon
4 Replies

7. Shell Programming and Scripting

awk assign output of array to specific field-number

With this script i want to print the output to a specific field-number . Can anybody help? awk 'NR=FNR{split(FILENAME,fn,"_");nr=$2;f = $1} END{for (i=1;i<=f;i++) print i,$fn=nr}' input_5.csv input_6.csvinput_5.csv 4 135 5 185 6 85 11 30input_6.csv 1 90 3 58 4 135 7 60 8 55 10... (1 Reply)
Discussion started by: sdf
1 Replies

8. Shell Programming and Scripting

Getting a specific date from cal output with AWK

Hi guys! I'll make this short... Is there any good way to get the day number that first matches the Monday column from the cal command output with awk (or any other text manipulator commands) ? I'm sorry if my question wasn't clear at all. For example... One cal output would be $... (6 Replies)
Discussion started by: Casey
6 Replies

9. Shell Programming and Scripting

how to include field in the output filename of awk

Im using awk and I want the output filename to contain the first field of the input file. Ex. 1 dddd wwwww 1 eeeee wwww 1 wwww eerrrr 2 eeee eeeeee I want the output files to be xxx1 and xxx2 Thank you (4 Replies)
Discussion started by: yahyaaa
4 Replies
Login or Register to Ask a Question