How to create concatenate a file in tab format


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to create concatenate a file in tab format
# 1  
Old 12-06-2007
How to create concatenate a file in tab format

Hi,

Do you know given a file which is SED at the same time, how to read it and AWK it in tabs format.

Means:-

I have an input file which is (at the same time perform sed):-

1
2
3
4
5
6
7

I would like to print out in tab format which is:-

1 2 3 4 5 6 7 ....

And another thing I observe in the past when I have data in tab format..when i perform operation on these fields it doesnt work. Because the tab data will go to new line and as a result the field number has got confused.

Anyone can help on this..Appreciate alot!


-Jason
# 2  
Old 12-06-2007
I am not sure I completely understand what you want, but you can use tr for the same purpose

cat $input_file | tr '\012' '\011'
# 3  
Old 12-06-2007
Actually my input is something like:-

1 10 blablabla
1 11 abababa
1 14 dslsdlsls
.
.
.
.
N

I have already used SED and cut to extract the first field and AWK to print the first element..however, I would like these data to be in tab format.

1 1 1 . . .N


I tried something like
cat bla.txt| sed '/^[^0-9-]/d' | cut f1 |awk '{print $1 "\t\t" }'
but it doesnt work.


Hope you could get I mean now.;Thanks.

-Jason
# 4  
Old 12-06-2007
.... with all the cat/sed/cut and awk-ing.... it's kinda hard to understand the desired final result.
Pls provided a sample input AND a desired output - make it as representative as possible.

I think you want this:
Code:
nawk '{printf("%s%s", (FNR==1) ? "" : "\t", $1} END{print ""}' myInputFile


Last edited by vgersh99; 12-06-2007 at 01:34 AM..
# 5  
Old 12-06-2007
awk '{printf ("%s\t", $1) ;}' bla.txt

or

cat bla.txt | cut -d ' ' -f 1 | tr -s '\012' '\011'

Hope it helps
J.
# 6  
Old 12-10-2007
Hi,

I tried to use the below command:-
cat bla.txt | sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |tr '' "//"| awk '{printf ("%s\t",$1); }'> output.txt


And I get this output.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

I would like to remove those whitespaces and get ultimately:-

0,0,0,0,0,0,0,0,0,0,0,0,0,0


Please advise. Thanks.


-Jason
# 7  
Old 12-10-2007
Hi,

Thanks.
I managed to get them by using
cat bla.txt | sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |awk '{printf ("%s",$1); }'> output.txt

It just works.

However I have one query,

Given that I have two separate folders which contain multiple bla.txt, how can i extract each of these bla.txt from two folders and the information is stored as one file (which is output.txt)?

Assuem i have Folder A and Folder B. In folder A, I have ten files with bla1.txt,bla2.txt....bla10.txt. Same goes in Folder B with bla11.txt to bla20.txt.

I would like to extract the information such that 0,0,0,............ for each of the txt found in two folders and merge in output.txt.

Please advise.

Thanks.

-Jason
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create movie from jpg (or other picture format) file

hi linux expert is there any program for create movie file from pictures file (like jpg)? Many Thanks samad (1 Reply)
Discussion started by: abdossamad2003
1 Replies

2. Shell Programming and Scripting

Needed touch command to create a file in the following format

needed touch command to create a file in the following format touch a_yyyymmdd_hhmmss (1 Reply)
Discussion started by: hemanthsaikumar
1 Replies

3. Shell Programming and Scripting

Need to create concatenate the shell variable with file content

Hi Guys, I have a file. Each record needs to inserted into a table. The table also have other columns which needs to be inserted with Shell variables. The following is the file. Error code None. Error Code 1 The shell script is having these variables. Name=Magesh Dep=Coding ... (1 Reply)
Discussion started by: mac4rfree
1 Replies

4. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

5. Shell Programming and Scripting

Create tab-delimited file of outputs - Perl

Title is very broad, but here's an outline of what I have done so far: - I have multiple subdirectories containing multiple *.fna files of DNA sequences - I've been able to traverse these subdirectories and create a tab-delimited text file (i.e. the association file) that shows the contents of... (1 Reply)
Discussion started by: shwang3
1 Replies

6. UNIX for Advanced & Expert Users

to create format file for bcp in

I want to create the format file for bcp in a file to the table. My Versions are: Unix: Sun OS, DB: Sybase. How can i create the format file. Is there any way to create the format by bcp command or some system sp. Please help. (3 Replies)
Discussion started by: Arunprasad
3 Replies

7. Shell Programming and Scripting

How to format or create a matrix report from file

Dear Unix champs, I have a input file as attached, i would like to create an report from the file as below FileType | EQUENS0001 | EQUENS0002 | EQUENS1100 | EQUENS0003 --------+-------------------------------------------------------- Msg No |... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

8. Shell Programming and Scripting

Using tab in script to create file of commands

from CLI pressing Tab and character like a shows result of the commands starting with a, can i use this in a script too and post the results to a file? thanks (1 Reply)
Discussion started by: tvrman
1 Replies

9. Shell Programming and Scripting

Help to Create this file format structure

This data comes form the table and exported into the file in this format File1 Format weboffercode1,sourcecode1,1,1,1,1,1,1 weboffercode1,sourcecode2,1,1,1,1,1,1 weboffercode1,sourcecode1,1,1,1,1,1,1 weboffercode1,sourcecode3,1,1,1,1,1,1 weboffercode1,sourcecode3,1,1,1,1,1,1 ... (4 Replies)
Discussion started by: enigma_83
4 Replies

10. Shell Programming and Scripting

Check whether a given file is in ASCII format and data is tab-delimited

Hi All, Please help me out with a script which checks whether a given file say abc.txt is in ASCII format and data is tab-delimited. If the condition doesn't satisfy then it should generate error code "100" for file not in ASCII format and "105" if it is not in tab-delimited format. If the... (9 Replies)
Discussion started by: Mandab
9 Replies
Login or Register to Ask a Question