I need help counting the fields and field separators using Nawk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need help counting the fields and field separators using Nawk
# 1  
Old 02-05-2008
I need help counting the fields and field separators using Nawk

I need help counting the fields and field separators using Nawk.

I have a file that has multiple lines on it and I need to read the file 1 at a time and then count the fields and field separators and then store those numbers in variables. I then need to delete the first 5 fields and the blank spaces.

example:
45 21 * * * run_cron /temp "daily_files.ksh"

I want to read the file that has this line and then write it to a new file with a line that looks like this:
run_cron /temp "daily_files.ksh"

The problem is that the the first 5 fields (which is what I really want to get rid of) are not the same for each line I am reading.

Any help is much appreciated. Thanks

Last edited by scrappycc; 02-05-2008 at 08:47 PM..
# 2  
Old 02-05-2008
Code:
bash-3.00# cat /tmp/tmp
45 21 * * * run_cron /temp "daily_teri_files.ksh"
45 21 * * * run_cron /test "weekly_teri_files.csh"

bash-3.00# while read one two three four five rest; do
> echo $rest | sed 's/"$/;run_mbpro teri-daily-recon.r"/'
> done < /tmp/tmp
run_cron /temp "daily_teri_files.ksh;run_mbpro teri-daily-recon.r"
run_cron /test "weekly_teri_files.csh;run_mbpro teri-daily-recon.r"

Is this what you were trying to do? You don't have to use nawk.
# 3  
Old 02-06-2008
Thanks for the answer

Yes that is exactly what I want to do. I will check it out and make sure it works for my big file. Thanks for the help!
# 4  
Old 02-06-2008
Quote:
Originally Posted by blowtorch
Code:
bash-3.00# cat /tmp/tmp
45 21 * * * run_cron /temp "daily_teri_files.ksh"
45 21 * * * run_cron /test "weekly_teri_files.csh"

bash-3.00# while read one two three four five rest; do
> echo $rest | sed 's/"$/;run_mbpro teri-daily-recon.r"/'
> done < /tmp/tmp
run_cron /temp "daily_teri_files.ksh;run_mbpro teri-daily-recon.r"
run_cron /test "weekly_teri_files.csh;run_mbpro teri-daily-recon.r"

Is this what you were trying to do? You don't have to use nawk.
if its a very large file as OP mentioned, running each line through a while loop and echoing part of each through sed might not be that efficient. it might be better to eliminate the while loop and let sed iterate the file instead since sed is internally "looping" over files anyway.
Also, awk is specifically designed to process structured data so it understands fields. using awk might be more "appropriate" in OP's case.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing out data with multiple field separators

I have a large file that I need to print certain sections out of. file.txt /alpha/beta/delta/gamma/425/590/USC00015420.blah.lt.0.01.str:USC00015420Y2017M10BLALT.01 12 13 14 -9 1 -9 -9 -9 -9 -9 1 2 3 4 5 -9 -9 I need to print the "USC00015420" and... (5 Replies)
Discussion started by: ncwxpanther
5 Replies

2. Shell Programming and Scripting

awk multiple fields separators

Can you please help me with this .... Input File share "FTPTransfer" "/v31_fs01/root/FTP-Transfer" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "Test" "/v31_fs01/root/Test" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "ENR California" "/v31_fs01/root/ENR California"... (14 Replies)
Discussion started by: greycells
14 Replies

3. Shell Programming and Scripting

Extract lines with min value, using two field separators.

I have a file with two ID columns followed by five columns of counts in fraction form. I'd like to print lines that have a count of at least 4 (so at least 4 in the numerator, e.g. 4/17) in at least one of the five columns. Input file: comp51820_c1_seq1 693 0/29 0/50 0/69 0/36 0/31... (6 Replies)
Discussion started by: pathunkathunk
6 Replies

4. Shell Programming and Scripting

Multiple long field separators

How do I use multiple field separators in awk? I know that if I use awk -F"", both a and b will be field separators. But what if I need two field separators that both are longer than one letter? If I want the field separators to be "ab" and "cd", I will not be able to use awk -F"". The ... (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

Counting Multiple Fields with awk/nawk

I am trying to figure out a way in nawk to 1) get a count of the number of times a value appears in field 1 and 2) count each time the same value appears in field 2 for each value of field 1. So for example, if I have a text file with the following: grapes, purple apples, green squash, yellow... (2 Replies)
Discussion started by: he204035
2 Replies

6. UNIX for Dummies Questions & Answers

Can one use 2 field separators in awk?

I have files such as n02-z30-dsr65-terr0.25-dc0.008-16x12drw-run1.cmd I am wondering if it is possible to define two field separators "-" and "." for these strings so that $7 is run1. (5 Replies)
Discussion started by: kristinu
5 Replies

7. UNIX Desktop Questions & Answers

awk Varing Field Separators

Hi Guys, I have small dilemma which I could do with a little help solving . I currently have text HDD S.M.A.R.T report which I have pasted below: smartctl 5.39 2008-10-24 22:33 (openSUSE RPM) Copyright (C) 2002-8 by Bruce Allen, http://smartmontools.sourceforge.net Device: COMPAQ... (2 Replies)
Discussion started by: bikerben
2 Replies

8. Shell Programming and Scripting

AWK multiple fields separators

I need to print the second field of a file, taking spaces, tab and = as field separators. ; for 16-bit app support MAPI=1 CMC=1 CMCDLLNAME32=mapi32.dll CMCDLLNAME=mapi.dll MAPIX=1 MAPIXVER=1.0.0.1 OLEMessaging=1 asf=MPEGVideo asx=MPEGVideo ivf=MPEGVideo m3u=MPEGVideo (2 Replies)
Discussion started by: PamPam
2 Replies

9. Shell Programming and Scripting

Multiple input field Separators in awk.

I saw a couple of posts here referencing how to handle more than one input field separator in awk. I figured I would share how I (just!) figured out how to turn this line in a logfile: 90000000000000000000010001 name... (4 Replies)
Discussion started by: kinksville
4 Replies

10. Shell Programming and Scripting

Awk Multiple Field Separators

Hi Guys, I'm tying to split a line similar to this:YO6-2000-30.htm: (3 properties found).......into separate columns, so effectively I need to check for a -, ., :, a tab and a space in the statement. Any help would be appreciated Thanks! (7 Replies)
Discussion started by: Tonka52
7 Replies
Login or Register to Ask a Question