The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multiple field separators in awk? (First a space, then a colon) doubleminus UNIX for Dummies Questions & Answers 3 04-27-2008 12:28 PM
Multiple input field Separators in awk. kinksville Shell Programming and Scripting 4 04-25-2008 02:12 PM
using nawk to concate the fields raychu65 UNIX for Dummies Questions & Answers 2 01-25-2008 02:26 AM
Append tabs at the end of each line in NAWK -- varying fields madhunk Shell Programming and Scripting 6 07-12-2006 03:20 PM
Awk Multiple Field Separators Tonka52 Shell Programming and Scripting 7 04-07-2004 06:37 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-05-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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 05:47 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 02-05-2008
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,328
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.
Reply With Quote
  #3  
Old 02-06-2008
Registered User
 

Join Date: Feb 2008
Posts: 6
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!
Reply With Quote
  #4  
Old 02-06-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by blowtorch View Post
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0