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
Flat File in HP-UX Krishnaramjis Shell Programming and Scripting 0 06-02-2008 11:24 PM
Help with a Flat File!!! kumarsaravana_s Shell Programming and Scripting 11 06-07-2007 11:15 PM
Help with a flat file!!! kumarsaravana_s Shell Programming and Scripting 3 04-16-2007 07:58 AM
XML to flat file balireddy_77 Shell Programming and Scripting 2 04-13-2007 05:57 AM
Converting Pivot file to flat file vskr72 Shell Programming and Scripting 2 10-18-2005 04:41 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 05-07-2008
Krishnaramjis Krishnaramjis is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
Flat file

Hi
I have a flat file looking this

QWER 2:35 7044 00001 ROUT 1188 EA SS
ASD 2:36 7044 00010 ROUT
BSD 2:37 7044 00011 ROUT
END
QWER 3:35 7044 00011 ROUT 1088 EA SS
ASD 3:36 7044 00010 ROUT
BSD 3:37 7044 00011 ROUT
END

If the redcolor value is 1088 then i need to change the values in the 3rd column (ie., 7044) to 9999 . How do i do script in HP -UX

Thanks
Krishna
  #2 (permalink)  
Old 05-07-2008
Krishnaramjis Krishnaramjis is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
one mort thing one set of order starts with QWER & ends with END . so I do want to change to entire 3rd column between QWER to END


Thanks
KRishna
  #3 (permalink)  
Old 05-07-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
How about this?

Code:
awk '
    # if the QWER line contains 1088, set the change flag to true
    $1=="QWER" { if ($6==1088) { change=1 } else { change=0 } }
    # if the change flag is set and the line has more than 3 fields, override the 3rd value
    change && NF > 3 { $3=9999 }
    # print the line
    1
' inputfile
  #4 (permalink)  
Old 05-08-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by Krishnaramjis View Post
Hi
I have a flat file looking this

QWER 2:35 7044 00001 ROUT 1188 EA SS
ASD 2:36 7044 00010 ROUT
BSD 2:37 7044 00011 ROUT
END
QWER 3:35 7044 00011 ROUT 1088 EA SS
ASD 3:36 7044 00010 ROUT
BSD 3:37 7044 00011 ROUT
END

If the redcolor value is 1088 then i need to change the values in the 3rd column (ie., 7044) to 9999 . How do i do script in HP -UX

Thanks
Krishna
Code:
sed '/1188/s/7044/9999/g' filename
Thanks
  #5 (permalink)  
Old 05-08-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Quote:
Originally Posted by namishtiwari View Post
Code:
sed '/1188/s/7044/9999/g' filename
That won't change the lines between QWER and END that do not contain 1088.
  #6 (permalink)  
Old 05-08-2008
Krishnaramjis Krishnaramjis is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 15
thanks alls. But Let me tell my requiremnet one more time .
QWER 2:35 7044 00001 ROUT 1188 EA SS
ASD 2:36 7044 00010 ROUT
BSD 2:37 7044 00011 ROUT
END
QWER 3:35 7044 00011 ROUT 1088 EA SS
ASD 3:36 sed '/1188/s/7044/9999/g' 00010 ROUT
BSD 3:37 7044 00011 ROUT
END
If the redcolor value is 1088 then i need to change the values in the 3rd column (ie., 7044) to 9999 . How do i do script in HP -UX

I want output as
QWER 2:35 7044 00001 ROUT 1188 EA SS
ASD 2:36 7044 00010 ROUT
BSD 2:37 7044 00011 ROUT
END
QWER 3:35 1088 00011 ROUT 1088 EA SS
ASD 3:36 1088 00010 ROUT
BSD 3:37 1088 00011 ROUT
END



Thanks
Krishna
  #7 (permalink)  
Old 05-08-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Using awk
Code:
awk '$6 ~ /1[0-1]88/{$3=9999}1' data.file
or sed
Code:
sed  '/1[0-1]88/s/7044/9999/g'   data.file

Last edited by danmero; 05-08-2008 at 01:10 PM.. Reason: add sed
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 01:50 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