Problem with cat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with cat
# 1  
Old 02-15-2011
Problem with cat

I am trying to use the following code:
Code:
cat *.txt > OutPutFile.txt

Using files with a expression in one single line that always end with " ; " something like this:
Block1.txt
Quote:
(7,((((1,2),3),(4,5)),6));
Block2.txt
Quote:
(2,((((1,2),3),(4,5)),6));
Block3.txt
Quote:
(9,((((1,2),3),(4,5)),6));
The expected result should be something like this:
OutPutFile.txt:
Quote:
(7,((((1,2),3),(4,5)),6));
(2,((((1,2),3),(4,5)),6));
(9,((((1,2),3),(4,5)),6));
My code works OK in this very small example but when I use it with my actual files (I have uploaded 3 files named block1.txt, block2.txt and block3.txt) containing very long, one-line expressions, the code does not produce the expected result (I am also uploading my outputfile). The problem is that when the expressions in the input files are too long, the code does not place them in individual lines. Instead, it generates a extremely long, single-line expression which I cannot use afterwards. I need to make sure that each expression is placed in an individual line one after another following the input file number order. Thus, the expression in block 1 should be the first one followed by block2 so on and so forth.
Any help will be greatly appreciate it!

Last edited by Xterra; 02-15-2011 at 05:29 AM..
# 2  
Old 02-15-2011
I think there might be problem with non-unix end of line character. Try
Code:
dos2unix *.txt
cat *.txt > OutPutFile.txt

# 3  
Old 02-15-2011
I think (at least from looking at the provided files) that the lines completely miss a line separator, and cat won't create any for you. Either have the generating application add that, or apply sed:
Code:
cat *.txt | sed -e 's/;/;\n/g' > OutPutFile.txt

This User Gave Thanks to pludi For This Post:
# 4  
Old 02-15-2011
Pludi

Thank you very, very much! sed fixed the problem!

Bartus,

Good to see you hanging around this place!
# 5  
Old 02-15-2011
Quote:
Originally Posted by pludi
I think (at least from looking at the provided files) that the lines completely miss a line separator, and cat won't create any for you. Either have the generating application add that, or apply sed:
Code:
cat *.txt | sed -e 's/;/;\n/g' > OutPutFile.txt

Do you need cat?

Code:
sed -e 's/;/;\n/g' *.txt> OutPutFile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with egrep and cat

Hello, I want to find some keywords in a dd image. I have created a keyword file (1.txt) and search the dd image using, cat /media/sdb1/test/c.dd.001 | strings | egrep -i --color -f 1.txt It works, But how can I get the file name and path? Many thanks. (7 Replies)
Discussion started by: yzy9951
7 Replies

2. Shell Programming and Scripting

Problem with cat

Hey all this is probably something simple but not sure why I am getting this error. Any help is appreciated. Expected output: $ ./ex_01.ksh word1 word2 word3 word4 arguments: word1 word2 word3 word4 Number of arguments: 4 what I am getting: ./ex_01.ksh word1 word2 word3 word4 cat:... (3 Replies)
Discussion started by: linuxn00b
3 Replies

3. Shell Programming and Scripting

problem using CAT command in PERL

Hi All, I was trying to run the cat command using perl SCRIPT for my daily reports. However cat command is not working in PERL. please help me. cat FILE1.txt |cut -d "|" -f1 >INPUT1.txt cat FILE2.txt|wc -l *9111*|>INPUT2.txt paste INPUT1,INPUT2 >OUTPUT.txt Thanks in advance ... (3 Replies)
Discussion started by: adaleru
3 Replies

4. Shell Programming and Scripting

Formatting problem with cat, egrep and perl

Hi guys I'm using the following script to change input file format to another format. some where I'm getting the error. Could you please let me know if you find out? cat input.txt|egrep -v ‘^#'|\ perl -ane ‘if (@F>3){$_=~/(chr.+):(\d+)\ s()/;print $1,”\t”,$2,”\t”,($2+35),”\n”}'\ > output.bed ... (1 Reply)
Discussion started by: repinementer
1 Replies

5. UNIX for Dummies Questions & Answers

Help me with a little problem with command cat

Hi I am having a little trouble understanding how to use this cat command. My question is the following: write a command to create a file called catFiles that contains three copies of the file catFile. If you can help me to understand how to create this, I would be very greatful. Thanks... (2 Replies)
Discussion started by: rushhour
2 Replies

6. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

7. UNIX for Advanced & Expert Users

Problem with cat with PERL Substitute

system("cat FILENAME | perl -e 'while(<>) { print $_;}'"); system("cat FILENAME | perl -e 'while(<>) { $_ =~ s/XXX/YYY/g; print $_;}'"); First command works fine but second command gives the following error: syntax error at -e line 1, near "{ =~" syntax error at -e line 1, near ";}"... (2 Replies)
Discussion started by: jingi1234
2 Replies

8. Shell Programming and Scripting

cat problem

Hello again; I have a file in this format ./this is/first/1 ./this is/second/2 ./this is/third/3 and i am using this file in a for loop with cat command like this for i in `cat directory.txt` do .......... done Bu there is a problem because my directory is "this is" but... (7 Replies)
Discussion started by: redbeard_06
7 Replies

9. Shell Programming and Scripting

cat file problem

Hi, I wnat to read a fiel line by line and store each line in a variabel, so I made a for loop: for i in `cat file` ; do #do sth. done; The problem is, that in the file, there are lines with only asterisks like this... (3 Replies)
Discussion started by: bensky
3 Replies

10. UNIX for Advanced & Expert Users

Problem with cat

On Solaris 5.8 in ksh, I have a sample.txt with contents A 105 305 B 205 405 C 100 198 ....................... when I do a cat sample.txt the O/P is exactly as above but when I do a echo `cat sample.txt` the O/P changes to A 105 305 B 205 405 C 100 198........... Everything is... (3 Replies)
Discussion started by: macrulez
3 Replies
Login or Register to Ask a Question