Individual Line processing in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Individual Line processing in awk
# 1  
Old 08-09-2011
Individual Line processing in awk

Hi ,

I have a file like
Code:
Activate your Membership now!
Dear Cyrus Every relationship needs nurturing. Including ours. 
2011-08-09T10:18:14Z
2011-08-09T10:18:14Z
tag:gmail.google.com,2004:1376659800396305843
T League
email@email.tleague.com
How to refresh a graphical display through bash script
hi i am just testing for the maximum capacity
2011-08-08T21:30:16Z
2011-08-08T21:30:16Z
tag:gmail.google.com,2004:1376611484483384709
me
cyrus.ic@gmail.com
NEWS: 'Write RTI' iPhone Mobile application launched
Dear RTIXT member, We have launched the free iPhone mobile 
2011-08-06T15:08:16Z
2011-08-06T15:08:16Z
tag:gmail.google.com,2004:1376406257464900735
admin@rtixt.org
admin@rtixt.org
[sunfeb2007:1634] Happy Friendship Day!
Hello My Friends, Happy Friendship Day Its fun to make fun of 
2011-08-06T10:23:28Z
2011-08-06T10:23:28Z
tag:gmail.google.com,2004:1376388339345447220
cyrus
cyrus22@gmail.com
OPENING FORC, C++ WITH UNIX AND ORACLE 
For Internal Use of Employer (Please don't delete or 
2011-08-05T09:55:57Z
2011-08-05T09:55:57Z
tag:gmail.google.com,2004:1376296011450947315
Ma Foi Management 
software.jobs@mafoirandstad.com

I want to parse every seven line at a time , where I have to choose only 1,2,6,7 lines to display in some formatted way .
Example for the first 7 lines the output should be like
Code:
You have got a mail from T League(email@email.tleague.com)
Sub: Activate your Membership now!
Desc:Dear Cyrus Every relationship needs nurturing. Including ours.

The above format goes for each set of 7 lines , the above example is for first 7 lines only.

Please avoid Perl in answer because I am not aware of that .
If this could be done in awk , as I am not able to find an answer.

Hope I am clear.

Thanks in advance.
# 2  
Old 08-09-2011
Try:
Code:
awk '!(NR%7-6){a=$0}!(NR%7-1){b=$0}!(NR%7-2){c=$0}!(NR%7){print "You have got a mail from "a"("$0")\nSub: "b"\nDesc: "c}' file

# 3  
Old 08-09-2011
I don't think awk oneliners should count as oneliners if they're wider than the screen.

how about this:
Code:
$ awk '{
        EOF=0;
        for (N=1; (!EOF) && (N<7); N++)
                if(!getline A[N]) EOF=1;

        if(!EOF)
        {
                printf("You have an email from %s (%s)\n", A[5], A[6]);
                printf("Sub: %s\n", $0);
                printf("Desc: %s\n\n", A[1]);
        }
}' < data
You have an email from T League (email@email.tleague.com)
Sub: Activate your Membership now!
Desc: Dear Cyrus Every relationship needs nurturing. Including ours.

You have an email from me (cyrus.ic@gmail.com)
Sub: How to refresh a graphical display through bash script
Desc: hi i am just testing for the maximum capacity

You have an email from admin@rtixt.org (admin@rtixt.org)
Sub: NEWS: 'Write RTI' iPhone Mobile application launched
Desc: Dear RTIXT member, We have launched the free iPhone mobile

You have an email from cyrus (cyrus22@gmail.com)
Sub: [sunfeb2007:1634] Happy Friendship Day!
Desc: Hello My Friends, Happy Friendship Day Its fun to make fun of

You have an email from Ma Foi Management  (software.jobs@mafoirandstad.com)
Sub: OPENING FORC, C++ WITH UNIX AND ORACLE
Desc: For Internal Use of Employer (Please don't delete or

$

It just retrieves 6 extra lines per loop to make up the difference so complex logic to print different lines on different loops isn't needed.

Last edited by Corona688; 08-09-2011 at 05:12 PM..
# 4  
Old 08-09-2011
Quote:
Originally Posted by Corona688
I don't think awk oneliners should count as oneliners if they're wider than the screen.
It fits nicely in one line on my 22" LCD Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Applying the same awk over a directory of files with individual file output

I am trying to apply an awk action over multiple files in a directory. It is a simple action, I want to print out the 1st 2 columns (i.e. $1 and $2) in each tab-separated document and output the result in a new file *.pp This is the awk that I have come up with so far, which is not giving me a... (6 Replies)
Discussion started by: owwow14
6 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

[awk] line by line processing the same file

Hey, not too good at this, so I only managed a clumsy and SLOW solution to my problem that needs a drastic speed up. Any ideas how I write the following in awk only? Code is supposed to do... For every line read column values $6, $7, $8 and do a calculation with the same column values of every... (6 Replies)
Discussion started by: origamisven
6 Replies

4. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

5. Shell Programming and Scripting

Working with individual blocks of text using awk

Hi, I am working with CVS log data and have some data as follows. RCS file: /cvsroot/eclipse/org.eclipse.debug.core/core/org/eclipse/debug/core/IBreakpointListener.java,v head: 1.14 branch: locks: strict access list: keyword substitution: o total revisions: 15; selected... (3 Replies)
Discussion started by: sandeepk1611
3 Replies

6. Shell Programming and Scripting

Apply 'awk' to all files in a directory or individual files from a command line

Hi All, I am using the awk command to replace ',' by '\t' (tabs) in a csv file. I would like to apply this to all .csv files in a directory and create .txt files with the tabs. How would I do this in a script? I have the following script called "csvtabs": awk 'BEGIN { FS... (4 Replies)
Discussion started by: ScKaSx
4 Replies

7. Shell Programming and Scripting

AWK: Remove spaces before processing each line?

Hi, all I have a file containing the following data: name: PRODUCT_1 date: 2010-01-07 really_long_name: PRODUCT_ABCDEFG I want to get the date (it is "2010-01-07" here), I could use the following code to do that: awk... (6 Replies)
Discussion started by: kevintse
6 Replies

8. Shell Programming and Scripting

reading a file inside awk and processing line by line

Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ... (6 Replies)
Discussion started by: Anteus
6 Replies

9. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

10. Shell Programming and Scripting

AWK Multi-Line Records Processing

I am an Awk newbie and cannot wrap my brain around my problem: Given multi-line records of varying lengths separated by a blank line I need to skip the first two lines of every record and extract every-other line in each record unless the first line of the record has the word "(CONT)" in the... (10 Replies)
Discussion started by: RacerX
10 Replies
Login or Register to Ask a Question