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
awk program to select a portion of a line anju Shell Programming and Scripting 3 01-11-2008 06:33 AM
Cutting a tab delimiter file vinod.thayil Shell Programming and Scripting 4 11-30-2007 03:38 PM
cutting columns if delimiter has more than one charecter mahabunta UNIX for Dummies Questions & Answers 9 09-14-2006 09:23 AM
erasing portion of line with sed (only once) gammaman UNIX for Dummies Questions & Answers 1 07-14-2005 09:40 PM
erasing portion of line with sed gammaman UNIX for Dummies Questions & Answers 5 07-10-2005 11:47 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 06-21-2008
ragavhere ragavhere is offline
Registered User
  
 

Join Date: Apr 2008
Location: Chennai,India
Posts: 79
Cutting a portion of a line seperated by pipe delimiter

Hi,

In the below line

a|b|10065353|tefe|rhraqs|135364|5347575
dgd|rg|4333|fhra|grhrt|46423|urdsgd

Here i want to cut the characters in between the second and third pipe delimiter and then between fifth and sixth delimiter and retain the rest of the line.

My output should be

a|b||tefe|rhraqs||5347575
dgd|rg||fhra|grhrt||urdsgd

How do i do this?
  #2 (permalink)  
Old 06-21-2008
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137
save the data in a files called test.out
run this awk command from commnd line
awk -F "|" 'BEGIN{OFS="|"}{$3=" ";$6=" ";print}' test.out
  #3 (permalink)  
Old 06-21-2008
ragavhere ragavhere is offline
Registered User
  
 

Join Date: Apr 2008
Location: Chennai,India
Posts: 79
This there a way to do this using a cut command?

Because the columns to be cut will be there in another paramfile. I have fixed width file as well as pipe delimited file. In case of fixed width file i will read the position to be cut from the param file and use the below commands. This is done in a script.

position=`grep "abc.txt" $path/paramfile | awk '{print$2}'`
cut -c$position abc.txt > file2.txt

Structure of param file will be like

abc.txt 1-5,68-

In case of delimited files if the same approach could be followed it would be easy.Because for each and every delimited file, the columns to be cut may vary.Hence i cannot hard the position to be cut in your code.

In case the file is a delimited file then the param file will have the information of which columns have to be retained.

like

file2.txt 1,3,4,7-

Last edited by ragavhere; 06-21-2008 at 05:46 AM.. Reason: Delimited file parm file structure
  #4 (permalink)  
Old 06-21-2008
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137
Can you please tell you requirement with one example it is not clear in your post.
If the fils is a delimeter file where the delimeter specified and in which column of parameter file ?

what is 68- ?? should it be 6-8 instead .... Make your requirement clear to assist you
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 04:23 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