Sponsored Content
Top Forums Shell Programming and Scripting Printing "END" before a new loop in AWK Post 302149862 by ccox85 on Saturday 8th of December 2007 09:43:55 AM
Old 12-08-2007
Question Clarification

I have been thinking about how to clarify, and due to a lack of familiarity I am struggling. My input is fairly complex:

PsyScope 1.2.5 PPC started: 11/07/07 12:35:10
Script file: FL 1024x768 v24 NEW NEW
Run on: Power Macintosh
Random Seed: 549174

RunNumber: 1
SubjectNumber: 14
SubjectName: 37492
Native Language: English
Do you speak this language regularly?: Yes

Input devices active: MOUSE KEY
Timing Device: Macintosh

440 Item2 TY 1 L UNR INCORRECT 1120 0
441 Item5 TY 1 R UNL INCORRECT 704 0
442 Item1 TY 1 L GOL CORRECT 577 0

This is the header and first 3 responses for one subject. Now picture a file with 20 subjects with 60 responses each, and it is one large txt file. My program reads through that file and prints out all this information in a a code that can be analyzed by another program very easily, in the format shown in my first post. I am finding it difficult to have awk print END each time it gets to a new subject entry at the end of the previous file (so it is actually at the end). This is just another bit of the code that needs to be there for the analysis.

Each subject is being saved to a new file by my awk script, so instead of one mondo file, in the end I have 20 files that are titled ("Syll"SubName".out"), where subject name is the variable that contains each subjects ID code. All of those individual files follow the format that I presented before.

Because I could not do it within my original script, performed this work around. I had my original script generate a list of all the subject codes in another output file, and then created another script to read from that file and append "END" to all the "Syll" output files.

This is the file I generate with the codes...
#List of Subject Codes
001: 37492
002: 36970
003: 37255
004: 36826
005: 37522
006: 37420
007: 37465
008: 37417
009: 36946
010: 37531

Here is my code for the script END.awk
# -- END.awk

{FS=":"}
{print "END" >> ("Syll" $2 ".out")}

And that actually does the trick. The only thing is that I am going to be giving this script back to my professor to use, and I want it to be as neat as possible, so if I can do this all in one script that would be awesome.

Alright, I hope this is all the information you need and more! I tried saving the subject code to a new field within the original input file, and letting it post there every loop, but it didnt work out as planned at all. Although I am learning the usefulness of awk through this project, I am definitely learning its weaknesses, so if I should be going about this with a different scripting language all together, please let me know!

THANK YOU FOR YOUR HELP!Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

3. Shell Programming and Scripting

append "awk command" to the end of each line

hi; this is my qqq.mos: l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-' l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-' l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-' ... i want to append;l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r"... (4 Replies)
Discussion started by: gc_sw
4 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

6. Shell Programming and Scripting

Get values from 2 files - Complex "for loop and if" awk problem

Hi everyone, I've been thinking and trying/changing all day long the below code, maybe some awk expert could help me to fix the for loop I've thought, I think I'm very close to the correct output. file1 is: <boxes content="Grapes and Apples"> <box No.="Box MT. 53"> <quantity... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

7. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

8. Shell Programming and Scripting

Removing "^M" from the end of a String (i.e. "Ctrl+M")?

Hello All, I have an Expect script that ssh's to a remote server and runs some commands before exiting. One of the commands I run is the "hostname" Command. After I run this command I save the output using this line in the code below... Basically it executes the hostname command, then I... (2 Replies)
Discussion started by: mrm5102
2 Replies

9. Shell Programming and Scripting

Using "for" loop within "awk"

Hi Team. I am trying to execute a simple for loop within an awk but its giving a different result. Below is the main code: awk '{for(i=1;i<=6;i++) print $i}'The result should be 1 2 3 4 5 6 but its not giving this result. Can someone please help? (3 Replies)
Discussion started by: chatwithsaurav
3 Replies

10. UNIX for Beginners Questions & Answers

Awk: Performing "for" loop within text block with two files

I am hoping to pull multiple strings from one file and use them to search within a block of text within another file. File 1PS001,001 HLK PS002,004 MWQ PS004,002 RXM PS004,006 DBX PS004,006 SBR PS005,007 ML PS005,009 DBR PS005,011 MR PS005,012 SBR PS006,003 RXM PS006,003 >SJ PS006,010... (11 Replies)
Discussion started by: jvoot
11 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy