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
Formatting Output dhanamurthy Shell Programming and Scripting 6 05-02-2008 11:43 AM
Formatting bdf output Cameron Shell Programming and Scripting 5 04-09-2008 09:05 AM
formatting output balaji_prk Shell Programming and Scripting 4 09-15-2007 09:23 AM
Formatting output illur81 Shell Programming and Scripting 3 10-13-2005 09:24 AM
Formatting the output Cameron Shell Programming and Scripting 7 02-15-2002 10:30 AM

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 06-25-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Formatting Output file

Hi, I have a file....

File1:

Num Name ID Place ADDR City Country
1024|Name1|ID1|Street1|ADDR1|Boston|UK
1025|Name2|ID3|Street2|ADDR2|London|USA

The above file is varaiable length file. I have to insert 2 values in every record of the above file.

Output:

1024|Name1|XX|ID1|Street1|ADDR1|YY|Boston|UK
1025|Name2|XX|ID3|Street2|ADDR2|YY|London|USA


As given above I need XX and YY values at third and Seventh column of every record in the file.

Please let me know how to do it. Thanks in advance.
  #2 (permalink)  
Old 06-25-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35
Thumbs up

Code:
# cat aaa
Num Name ID Place ADDR City Country
1024|Name1|ID1|Street1|ADDR1|Boston|UK
1025|Name2|ID3|Street2|ADDR2|London|USA

# awk  'FS=OFS="|" {if (NR == 1) print $0; else print $1,$2,"XX",$3,$4,$5,"YY",$6,$7}' aaa
Num Name ID Place ADDR City Country
1024|Name1|XX|ID1|Street1|ADDR1|YY|Boston|UK
1025|Name2|XX|ID3|Street2|ADDR2|YY|London|USA
  #3 (permalink)  
Old 06-25-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Hi, Thanks for the reply.I have given the above command .... Its working for all the records except for first record......... Please let me know how to append the values for first record also.
  #4 (permalink)  
Old 06-26-2008
ynir ynir is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 35
Of course it skipped the first line - you wrote it was supposed to be:
Num Name ID Place ADDR City Country

If you want to apply the rule to all line, ignore the condition that refers to the first line:
if (NR == 1) ...
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:15 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