Shell program:Help required on file formating


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell program:Help required on file formating
# 1  
Old 01-31-2008
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  
Old 01-31-2008
I assume thats an in-place file editing

if so,

Code:
%s/|/ |/g

replacing "|" to " |" < space and a pipe >
# 3  
Old 02-01-2008
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  
Old 02-01-2008
Can you post your command or program here, so that we could give some idea. ?
# 5  
Old 02-01-2008
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  
Old 02-04-2008
Data

Can anybody help me with my query?
# 7  
Old 02-04-2008
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required with a file rename shell script

Hello everyone, Posting here after a long time, been away from unix world lately and it seems I have forgotten my shell scripting completely. I have a requirement where a csv file contains following columns: Full Registration VIN Stock... (14 Replies)
Discussion started by: tayyabq8
14 Replies

2. Shell Programming and Scripting

help required in program

I have below code, i need to modify it, to search for files (*.php,*.css,*.html) in those directores which have 777 permission, how to modify this code. Because it is moving all files. while true do sleep 60 DATE=$(date +%Y-%m-%d) # Creates dir only if it... (21 Replies)
Discussion started by: learnbash
21 Replies

3. Shell Programming and Scripting

Help me! Format output file using shell program

Hi, I have following input file. I want to generate output file in specific format using shell program. The input file has atleast few thousands of lines, the below are some sample lines. Input file: "ORDER NO"|"ORDER AMT"|"LINE ITEM"|"LINE AMT"|"SALES COMMISION %" ORD3456|5000|LIN345|30|25%... (8 Replies)
Discussion started by: dsubha
8 Replies

4. Programming

Why is required to leave an empty line at the end of a C program?

I know it looks like a stupid question, but i really wanna know the reason. Actually, i think it's because the c compiler will detect it as the end of file "EOF" of the program, but, am i wrong? because it compiles it anyway, but keep showing warnings like "no new line at the end of file". I... (8 Replies)
Discussion started by: semash!
8 Replies

5. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

6. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

7. UNIX for Dummies Questions & Answers

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 (1 Reply)
Discussion started by: udiptya
1 Replies

8. Shell Programming and Scripting

Urgent help required in deleting a line without opening a file usinga shell script

Hi, I need a help in deleting a line matching a particular pattern in a file using shell script without opening the file. The file is a .c/.cpp file. Is it possible? Thanks (6 Replies)
Discussion started by: naan
6 Replies

9. Shell Programming and Scripting

Very Urgent help required in Shell Program

How do I Ftp, and rename multiple files in one unix script. I have to send it with .tmp extension , then rename it to .txt after FTP is done . I need to do a Mass rename of more than 1 file in a shell script , Urgent help required. (1 Reply)
Discussion started by: Suppandi
1 Replies

10. Programming

A C program required for portability

I have to solve a problem for my wife who is engaged in Research in Breast Cancer. 1. She has frequently to search a long single line of alphabetic characters (lower case) for an exact match of a string. e.g.... (1 Reply)
Discussion started by: nmsinghe
1 Replies
Login or Register to Ask a Question