Creating a tabulated file from content of 2 or more files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a tabulated file from content of 2 or more files
# 1  
Old 08-08-2005
Creating a tabulated file from content of 2 or more files

Hi all

I need specific fields from a file to be tabulated into a single file.
I have a file with the following :-

FIELD1 InfoA FIELD2 InfoB
FILED3 InfoC

FIELD1 InfoD FIELD2 InfoE
FIELD3 InfoF

The output I would like is as follows :-
InfoA|InfoB|InfoC
InfoD|InfoE|InfoF

Any ideas. I have though of using grep and cut to create a file for each field and then use sed to read each line and echo it into a single line, however have not been able to.

Thx

J
# 2  
Old 08-08-2005
file:
Code:
FIELD1 InfoA FIELD2 InfoB
FILED3 InfoC

FIELD1 InfoD FIELD2 InfoE
FIELD3 InfoF

result:
Code:
InfoA InfoB InfoC
InfoD InfoE InfoF

Code:
awk ' {
        if(NR % 3 == 0) {continue}        
        if(NF > 2) 
        {
                    printf("%s %s ", $2, $4)
                    continue
        }
        printf("%s\n", $2)        
      } ' filename

# 3  
Old 08-08-2005
Jim's code appeared to be correct, so I condensed it:
Code:
4==NF { printf "%s|%s|", $2, $4 }
2==NF { print $2 }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a file in more files based on score content

Dear All, I have the following file tabulated: ID distanceTSS score 8434 571269 10 10122 393912 9 7652 6 10 4863 1451 9 8419 39 2 9363 564 21 9333 7714 22 9638 8334 9 1638 1231 11 10701 918 1000 6587 32056 111 What I would like to do is the following, create 100 new files based... (5 Replies)
Discussion started by: paolo.kunder
5 Replies

2. Shell Programming and Scripting

Creating two files out of one file

Hi members, I have a file with lots of text like this: asdsfkm dfsfomnow i want to extract only the rows with HUMAN as its 1st column for this I used : ruby -ne 'print if /^Human/; exit if /^TER/' $line | awk 'print $1, "\t"$2, "\t"$3, "\t"$4, "\t"$5}' >$line"new" This is creating a file... (1 Reply)
Discussion started by: CAch
1 Replies

3. Shell Programming and Scripting

Comparing two files and creating a new file

Hi, I want to compare two files based on the data in their first column. Both the files are not equal in their number of columns and number of entries or rows. The entries (only the first column) of the file1 should be compared with the entries (only the first column) of the file2. If the... (3 Replies)
Discussion started by: begin_shell
3 Replies

4. Shell Programming and Scripting

search for content in files. Name of files is in another file. Format as report.

Hi I have multiple files in a folder and one file which contains a list of files (one on each line). I was to search for a string only within these files and not the whole folder. I need the output to be in the form File1<tab>string instance 2<tab> string instance 2<tab>string instance 3... (6 Replies)
Discussion started by: pkabali
6 Replies

5. Shell Programming and Scripting

comparing 2 files and creating third file with uncommon content

I want to compare 2 files and create third file with uncommon content. e.g. file1 ajay suhas tom nisha vijay mahish file2 ajay suhas tom nisha expected output file content vijay mahish Is it possible in single command ? Thanks, Ajay (6 Replies)
Discussion started by: ajaypatil_am
6 Replies

6. Shell Programming and Scripting

copy content of file to another files from certain position

Hello Guys I have a directory of xml files (almost 500 ) Now in each xml file 3 new attributes will be added which are in a different single file Is there any way I can copy the whole content of single file at 6th line of all the files in the directory . Thanks a lot!!! (7 Replies)
Discussion started by: Pratik4891
7 Replies

7. UNIX for Dummies Questions & Answers

creating text file with content from script

hi, can somebody tell me how I can create a text file with content from Bash script. The file should be prefilled with information such as current date and time then leaving the user ability to input more data right below those prefilled content. thank you :) (0 Replies)
Discussion started by: s3270226
0 Replies

8. UNIX for Dummies Questions & Answers

Read an ascii as cell-tabulated form

Hi Guys, I was wondering if it is possible to load a space-tabulated ascii as a "cell-tabulated form", something like excel. I have the following information: tracl tracr fldr ep cdp cdpt nhs duse scalel scalco sx sy counit ns dt igi year day hour minute sec timbas 1 1 1 1 1 1 1 1 -1000... (9 Replies)
Discussion started by: Gery
9 Replies

9. Shell Programming and Scripting

ls > file - Creating file containing the list of all files present in a directory

Hi All, I need to create a file which contains the list of all the files present in that directory. e.g., ls /export/home/user/*.dat > list_file.dat but what i am getting is: $ ls /export/home/user/*.dat > list_file.dat /export/home/user/*.dat: No such file or directory But I have... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

10. Shell Programming and Scripting

creating files and getting input from another file

I have a file where i have files name with absolute path. Ex: files.dat and contents are: /root/xy/yz/zz/abc.txt /root/xx/yy/zz/ac.txt /root/xz/yz/zx/bc.txt /root/xy/yz/zx/abcd.txt now i want to create all above files(dummy files and can be 0 byte). i thought of using touch but it doesn't... (10 Replies)
Discussion started by: ajayyadavmca
10 Replies
Login or Register to Ask a Question