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
Changing one column of delimited file column to fixed width column manneni prakash Shell Programming and Scripting 5 06-22-2009 05:27 AM
How to get the first column from the txt file using unix command? psiva_arul Shell Programming and Scripting 4 01-08-2009 10:36 AM
Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK? rickdini UNIX for Dummies Questions & Answers 6 09-29-2008 02:35 AM
trim file tungaw2004 UNIX for Dummies Questions & Answers 1 09-15-2007 06:05 AM
trim leading zero in certain column in a string dngo UNIX for Dummies Questions & Answers 2 04-01-2007 02:30 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 01-14-2009
Amit.Sagpariya Amit.Sagpariya is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 111
How to trim a 419th column in UNIX file.

Hi All,

I have a UNIX file, which has Total of 532 column, each delimited with ^~^. One of the column (419) is 202 character long. In real case, it should be 22 character long.

cut -d~ -f419 filename

^404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040402 D2D404D4450444040604048E040404240C0404040
42404040404040584042544040404044404040404040404040404040404040^

I need to trim it to 22 character. at the begining & end ^ sould come. I have searched & found following link.
Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

But when i execute the command given here, AWK is not supporting it.

Can some one help me?
  #2 (permalink)  
Old 01-14-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

What does "not supporting it" mean? What does happen? What did you expect to happen? What did you want to happen?

What is the exact script you are running?

  #3 (permalink)  
Old 01-14-2009
Amit.Sagpariya Amit.Sagpariya is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 111
It gives following error.

$ awk 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419

all record(columns) are delimited with ^~^ & there are 532 columns.

From my data file i want to trim 419th column from 202 characters to 22 characters , so that i can load it.
  #4 (permalink)  
Old 01-14-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

You must tell awk that your fields (not records) are tilde delimited:

Code:
awk -F~ 'NR == 1 { .... } ....' ....
  #5 (permalink)  
Old 01-14-2009
Amit.Sagpariya Amit.Sagpariya is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 111
It gives same error.

$ awk -F~ 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419

or

$ awk -F^~^ 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419
Sponsored Links
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk, trimming

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 03:07 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