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
NAWK Script not working fine dheeraj19584 Shell Programming and Scripting 3 06-12-2008 04:36 AM
how to access values of awk/nawk variables outside the awk/nawk block? saniya Shell Programming and Scripting 5 05-13-2008 04:37 AM
nawk/ksh help DeltaX Shell Programming and Scripting 0 03-06-2008 11:54 AM
nawk use ctap UNIX for Advanced & Expert Users 2 01-17-2008 02:45 AM
help with Awk or nawk Gerry405 UNIX for Dummies Questions & Answers 2 11-28-2005 09:00 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2005
Registered User
 

Join Date: Jun 2001
Location: Tehran, Iran
Posts: 61
Unhappy help need on nawk script

Dear experts
I have a big file containing several profiles each flagged with "PROFILE" at the beginning of each one. I am trying to use the following command in cshell to seperate each profile and save each one in seperate file. I wrote a script as following:

nawk -v i=0 '{if($1~/PROFILE/) i=i+1, print $0 }' filename > filename$i

I was expecting that it will create different files like file1, file2, ... for each profile but it is not the case. It may need to introduce variable i somehow to shell environment but how can I manage " i " in nawk command can be recognized in shell environment.
Thanks in advances for your advises.
Reza
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-04-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Code:
nawk '$1 ~ /PROFILE/ {out=FILENAME ++i; print $0 > out}' filename
Reply With Quote
  #3 (permalink)  
Old 02-04-2005
Registered User
 

Join Date: Jun 2001
Location: Tehran, Iran
Posts: 61
Quote:
Originally Posted by vgersh99
Code:
nawk '$1 ~ /PROFILE/ {out=FILENAME ++i; print $0 > out}' filename
Thanks a lot for your prompt reply. It works. Just as a question is it possible if you please recommend a good reference in unix scripting that you prefer.
Reply With Quote
  #5 (permalink)  
Old 04-14-2008
Registered User
 

Join Date: Apr 2008
Posts: 1
could you please tell me how to convert a horizontal line into a vertical line using UNIX.
I have 07:37:37 07:31:29 07:21:18 07:08:55 07:08:30 07:00:34 06:53:40 this in a file
.

Help me in getting it into below format.

07:37:37
07:31:29
07:21:18
07:08:55
07:08:30
07:00:34
06:53:40
Reply With Quote
  #6 (permalink)  
Old 04-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,084
Code:
tr ' ' '
' <file
That is, convert space (in single quotes) to newline (in single quotes).

Edit: didn't notice you were hijacking somebody else's thread. Please don't do that.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:49 PM.


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

Content Relevant URLs by vBSEO 3.2.0