The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 03:28 PM
Multiple input field Separators in awk. kinksville Shell Programming and Scripting 4 04-25-2008 05:12 PM
using nawk to concate the fields raychu65 UNIX for Dummies Questions & Answers 2 01-25-2008 05:26 AM
Append tabs at the end of each line in NAWK -- varying fields madhunk Shell Programming and Scripting 6 07-12-2006 06:20 PM
Awk Multiple Field Separators Tonka52 Shell Programming and Scripting 7 04-07-2004 09:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-05-2008
scrappycc scrappycc is offline
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 08:47 PM..
  #2 (permalink)  
Old 02-05-2008
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 02-06-2008
scrappycc scrappycc is offline
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!
  #4 (permalink)  
Old 02-06-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0