Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-03-2008
Registered User
 

Join Date: Jan 2008
Posts: 47
print a file with one column having fixed character length

Hi guys,
I have tried to find a solution for this problem but couln't. If anyone of you have an Idea do help me.

INPUT_FILE
with three columns shown to be separated by - sign
A5BNK723NVI - 1 - 294
A7QZM0VIT - 251 - 537
A7NU3411V - 245 - 527

I want an output file in which First column should have only fixed no. of characters say 7 or whatever no. I need and rest of the columns should be the same.

OUTPUT_FILE
A5BNK72 - 1 - 294
A7QZM0V - 251 - 537
A7NU341 - 245 - 527

Your help is highly appreciated.
Sponsored Links
  #2 (permalink)  
Old 10-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652

Code:
awk -F " - " 'BEGIN { OFS=FS } { $1=substr($1,1,7) }1' file

  #3 (permalink)  
Old 10-03-2008
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 4,962
With sed:


Code:
sed 's/\(.......\).*\( -.*-.*\)/\1\2/' file

Sponsored Links
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 Off


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 06:27 AM
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 9 12-04-2008 04:04 PM
convert fixed length file to CSV tbtbs Shell Programming and Scripting 12 08-12-2008 10:54 AM
Comparing column of variable length anf fixed width file manneni prakash Shell Programming and Scripting 5 06-25-2008 02:46 AM
use SQL loader to dump a fixed length file in to DB anumkoshy Shell Programming and Scripting 2 10-10-2007 06:53 AM



All times are GMT -4. The time now is 07:30 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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0