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 > 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
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 08:34 AM
Help required on file formating udiptya UNIX for Dummies Questions & Answers 1 01-31-2008 09:25 AM
Urgent help required in deleting a line without opening a file usinga shell script naan Shell Programming and Scripting 6 07-20-2006 03:42 AM
Very Urgent help required in Shell Program Suppandi Shell Programming and Scripting 1 12-09-2005 08:33 AM
A C program required for portability nmsinghe High Level Programming 1 09-20-2002 12:34 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-31-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Shell program:Help required on file formating

I have two files file1 and file2 as shown below:
file1:
name
nameabc
bcd
nameabcdefg


file2:
age
age1111
age2345
age6743

I have pasted one file on the other with the delimiter "|" and the resulttant file is:
name|age
nameabc|age1111
bcd|age2345
nameabcdefg|age6743

but I want it to be formatted like this:
name |age
nameabc |age1111
bcd |age2345
nameabcdefg |age6743

I tried it with "\t" but since the length of name can vary the number of tabs is not constant. Can anybody give a solution to this?
  #2 (permalink)  
Old 01-31-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
I assume thats an in-place file editing

if so,

Code:
%s/|/ |/g
replacing "|" to " |" < space and a pipe >
  #3 (permalink)  
Old 02-01-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Hi what u suggested I have tried that already but the thing is I want to position them the parameters one below the other something like shown below

name\t\t\t\t\t\t\t|age
nameabc\t\t\t\t\t|age1111
bcd\t\t\t\t\t\t\t\t|age2345
nameabcdefg\t\t\t|age6743
  #4 (permalink)  
Old 02-01-2008
ynilesh's Avatar
ynilesh ynilesh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore, India.
Posts: 222
Can you post your command or program here, so that we could give some idea. ?
  #5 (permalink)  
Old 02-01-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
file1:
name
nameabc
bcd
nameabcdefg


file2:
age
age1111
age2345
age6743

Above given are my two files. I have issued a command like

echo "`paste -d'|' file1 file2`" > file3

I am getting file3 as:
name|age
nameabc|age1111
bcd|age2345
nameabcdefg|age6743

whereas I want the values to start from a single column. Something like

file3:
name\t\t\t\t\t\t\t|age
nameabc\t\t\t\t\t|age1111
bcd\t\t\t\t\t\t\t\t|age2345
nameabcdefg\t\t\t|ge6743

All of the data in red should start from a fixed column!
  #6 (permalink)  
Old 02-04-2008
udiptya udiptya is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 24
Unhappy

Can anybody help me with my query?
  #7 (permalink)  
Old 02-04-2008
sjday sjday is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 9
Possible solution

Create a awk file called neatcols with the following contents

{
printf "%-20s %s\n", \
$1, substr($0, index($0,$2))
}

then run it in

awk -f neatcols file3 > file4
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 On




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

Content Relevant URLs by vBSEO 3.2.0