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
# 8  
Old 12-10-2007
Hi,

Another problem I faced is in the below cases of

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

I would like to include the first element with filename which is
something like

bla, 0,0,0,0,0,0,............
test,0,0,0,1,0,.............

and so on.

I tried

awk '
{
printf("%s",$1);
printf("\n");

}'>output.txt

But it gives me something like

0,
0,
0,
0,
0,

I would like to output something like:-


bla, 0,0,0,0,0,0,............ "\n(new line)"
test,0,0,0,1,0,.............

Please advise. Thanks.

Rgrds,
Jason
# 9  
Old 12-10-2007
Code:
awk '
FNR==1 {
   out=substr(FILENAME, 1, index(FILENAME, ".txt")-1)
}
{
   printf("%s%s%s\n",out, OFS,$1);
}' *.txt > output.txt

# 10  
Old 12-10-2007
Hi,

I tried on the below code but it doesnt work at all. The execution get stuckSmilie

Actually, I can get the string name for filename manually by using
filters=${x:37}

And I would like to read in multiple files of .txt.And end up having these string on the front of the numbers which are extracted for each file.

For example:-
I have 2 files which is bla1.txt and bla2.txt which contains all the numbers to parse horizontally with "," in another new file; called output.txt

In the output.txt, it would be expected to have :-
bla1,1,0,0...........
bla2,1,0,1,...........

I have this code:-

echo $PWD
for x in /home/*; do

filters=${x:37}

cat *.txt| sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |awk '
{

printf ("%s",$1);

}

{

printf("\n");}'> output.txt

But I do not know where to include the $filters in front of each file (.txt) parsed. Besides, the "\n" doesnt work for each file parsed.

Please advise. Thanks alot.


-Jason
# 11  
Old 12-11-2007
Hi,

I managed to it works. Something to share with you guys.

I used the number ${t:37} to get the number of the file

The code looks below:-

cat b$number| sed 's/^[ ]*//' |sed 's/^-/0/'|sed 's/^#####/0/'|sed '/^[^0-9-]/d'|tr ':' "," |awk '{printf ("%s",$1);}'| awk 'FNR == 1 && NR > FNR { print "" } { print $0 ",bla" }' >>output.txt

basically sed the files and print the first field of the file and at the end just append the "bla" behind each file read.

Appreciate alot help. Thanks again!

-Jason
# 12  
Old 12-11-2007
Hi vgersh and all,

I have another query related to below ones.

Basically the command below just seeded some of the elements in a file.
I still missed out one thing which I would like to remove the first five lines of each file before awk is performed.

In other words, I only want to consider only from first 6th line on wards.

Please advise. THanks.

-Jason
# 13  
Old 12-11-2007
I managed to get it work anyhow by doing on:-

sed '1,5 d' //which is to remove first 5 lines of the file


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