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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 08:30 AM
top output new2ss UNIX for Advanced & Expert Users 4 03-11-2008 04:58 AM
awk output useless79 Shell Programming and Scripting 3 09-03-2007 11:21 AM
FTP Output lindeng UNIX for Dummies Questions & Answers 9 02-10-2004 10:18 PM
ps output Shobhit UNIX for Advanced & Expert Users 2 03-10-2002 09:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-04-2007
milo milo is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 32
how to get output by awk

Hi all,

I have an input file like
trk 1 soft
trk 1 get
trk 1 get
trk 1 soft


Want to have output file contains line number of lines which have "soft" string from input like
1
4


Then, create new file from output to
ui 1 stop
ui 4 stop


Tried using with awk, still not got result.

Appreciate all your help. Thanks.
  #2 (permalink)  
Old 02-04-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131

Code:
$ cat data
trk 1 soft
trk 1 get
trk 1 get
trk 1 soft
$ awk '/soft/ { print "this", NR, "that" }' data
this 1 that
this 4 that
$

  #3 (permalink)  
Old 02-04-2007
milo milo is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 32
Thanks Perderabo, that's so simple and great!

But, out put file have all in one line... I wish they are separated lines... each line for one command...
  #4 (permalink)  
Old 02-04-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by milo
Thanks Perderabo, that's so simple and great!

But, out put file have all in one line... I wish they are separated lines... each line for one command...
strange - my output is as Perderabo's:

Code:
this 1 that
this 4 that

what output are you seeing and what are you expecting?
  #5 (permalink)  
Old 02-04-2007
milo milo is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 32
It's working fine now. your output is what I expected. I got mistake when check output by echo command.

details expected output file I want is
tappman -c '#'mps.1 -l 1 stop
tappman -c '#'mps.1 -l 4 stop


so I used below command
awk '/SOFTBLOCK/ { print "tappman -c '#'mps.1 -l", NR, "stop" }' cicStatus > runApps

But it didn't work since command didn't accept ' ' covered #. Tried to use \ and "" to cover ', but it still not work.

Thanks for ur kind help.

Last edited by milo; 02-04-2007 at 11:49 PM..
  #6 (permalink)  
Old 02-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
SED solution


Code:
sed -n '/soft/=' f | sed "s/.*/tappman -c '#'mps.1 -l & stop/"

  #7 (permalink)  
Old 02-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by milo
It's working fine now. your output is what I expected. I got mistake when check output by echo command.

details expected output file I want is
tappman -c '#'mps.1 -l 1 stop
tappman -c '#'mps.1 -l 4 stop


so I used below command
awk '/SOFTBLOCK/ { print "tappman -c '#'mps.1 -l", NR, "stop" }' cicStatus > runApps

But it didn't work since command didn't accept ' ' covered #. Tried to use \ and "" to cover ', but it still not work.

Thanks for ur kind help.
awk -v qt="'" '/SOFTBLOCK/ { print "tappman -c " qt "#" qt "mps.1 -l", NR, "stop" }' cicStatus > runApps
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 11:39 PM.


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