The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enterprise Unix Roundup: The Ghost of Unix Future - Server Watch iBot UNIX and Linux RSS News 0 12-19-2007 12:20 PM
Running UNIX commands remotely in Windows box from Unix box – avoid entering password D.kalpana UNIX for Dummies Questions & Answers 1 04-20-2007 06:24 AM
FTP script for sending a file from one unix directory to another unix server director raja_1234 Shell Programming and Scripting 1 11-30-2006 07:57 AM
Unix Sco Open Server, Windows Computers Problem Access Unix Shared Files Help!!!!! haggo Filesystems, Disks and Memory 2 08-23-2006 12:39 PM
Unix History Question: Why are filenames/dirnames case sentsitive in Unix? deckard UNIX for Dummies Questions & Answers 3 03-26-2005 01:59 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 08-14-2008
kolesunil kolesunil is offline
Registered User
  
 

Join Date: May 2008
Posts: 8
Unix

I have a data in a file called data1.dat like this:
70815|1418|V|F70816|1418|V|M
70817|1418|V|M70818|1418|V|F
70819|1418|V|M

I want the output like this:
70815|1418|V|F
70816|1418|V|M
70817|1418|V|M
70818|1418|V|F
70819|1418|V|M



Thanks in advance
  #2 (permalink)  
Old 08-14-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
try this:
Code:
awk -F '|' '{print $1 "|" $2 "|" $3 "|" substr($4,0,1)}' data1.dat

  #3 (permalink)  
Old 08-15-2008
runmeat6 runmeat6 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 11
Quote:
Originally Posted by Yogesh Sawant View Post
try this:
Code:
awk -F '|' '{print $1 "|" $2 "|" $3 "|" substr($4,0,1)}' data1.dat
Starting with the above code, it needs to go a little bit further to yield the entirety of the desired output. Perhaps
Code:
awk -F'|' '{print $1 "|" $2 "|" $3 "|" substr($4,0,1) "\n" substr($4,2) "|" $5 "|" $6 "|" $7}' data1.dat | grep -v '|||'

will work. The grep at the end handles any lines like the last line in the sample in which there are one instead of two records.
Closed Thread

Bookmarks

Tags
awk substr

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:27 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