How to print the words in the same line with space or to the predefined line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print the words in the same line with space or to the predefined line?
# 1  
Old 02-18-2010
Bug How to print the words in the same line with space or to the predefined line?

HI,

Code:
cat test

abc

echo "def" >> test

output is

Code:
cat test

abc
def

the needed output is

Code:
cat test

abc def

and so on

thanks in advance

Last edited by zxmaus; 02-18-2010 at 04:38 AM.. Reason: added code tags
# 2  
Old 02-18-2010
Code:
cat > test << END
abc def

some more text
END



---------- Post updated at 01:15 PM ---------- Previous update was at 01:10 PM ----------

Sorry, seems I misunderstood the problem.

In that case, you need to edit your line with utilities like, sed,ed,awk, etc
# 3  
Old 02-18-2010
with awk command

Code:
awk '{ORS=" "}1' test

# 4  
Old 02-18-2010
replace
echo "def" >> test
by
echo -n " def" >> test
Don't forget the space !
# 5  
Old 02-18-2010
Quote:
Originally Posted by frans
replace
echo "def" >> test
by
echo -n " def" >> test
Don't forget the space !
"-n" suppress the trailing newline i guess..

Last edited by clx; 02-18-2010 at 03:09 PM..
# 6  
Old 02-18-2010
Excellent !!!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

2. Shell Programming and Scripting

Search words in a line and print next 15 lines.

I have a text file ( basically a log file) and i have 2 words (alpha, beta), Now i want to search these two words in one line and then print next 15 lines in a temp file. there would be many lines with alpha and beta But I need only last occurrence with "alpha" and "beta" and next 15 lines. ... (4 Replies)
Discussion started by: kashif.live
4 Replies

3. Shell Programming and Scripting

awk until blank space and print next line

Hello and Happy New Year 2012! I have this example: 1,2,3 4,5,6 7,8,9 For that, I'm trying to get: 1,2,3 4,5,6 7,8,9 for that, I think this might work but doesnt work so far: awk '{for(i=1;i=NF;i++);sub(/\//,"",$i);print $i}' myfile (2 Replies)
Discussion started by: Gery
2 Replies

4. Shell Programming and Scripting

print number of words in each line

Hi, Please suggest a way to print number of words in the end of each line. <input file> red aunt house blue sky bat and ball game <output file> red aunt house 3 blue sky 2 bat and ball game 4 Thanks! (2 Replies)
Discussion started by: mira
2 Replies

5. Shell Programming and Scripting

Remove all words after first space from each line

My file looks like: asd absjdd sdff vczxs wedssx c dasx ccc I need to keep asd sdff wedssx dasx How do I do that experts?:wall::wall: (1 Reply)
Discussion started by: hakermania
1 Replies

6. Shell Programming and Scripting

Count and print all repeating words in a line

Gurus, I have a file containing lines like this : Now, number of words in each line varies. My need is, if a word repeats in a line get it printed. Also total number of repeats. So, the output would be : Any help would be highly appreciated. Thanks & Regards (5 Replies)
Discussion started by: AshwaniSharma09
5 Replies

7. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

8. Shell Programming and Scripting

Print two matched words from the same line

Hi experts I need to pick 2 matched words from the same line..... I have given below an example file eg: O14757 hsa04110 hsa04115 2 P38398 hsa04120 1 O15111 hsa04010 hsa04210 hsa04920 hsa04620 hsa04660 hsa04662 hsa05200 hsa05212 hsa05221 hsa05220 hsa05215 hsa05222 hsa05120 13 O14920... (4 Replies)
Discussion started by: binnybio
4 Replies

9. Shell Programming and Scripting

print only last two words of a line

can u help me out to print last two words of each sentence of a file. for example. contents of input file: i love songs my favourite songs sent songs all kind good buddy Ouput file should contain: love songs favourite songs sent all kind good buddy (5 Replies)
Discussion started by: pradeepreddy
5 Replies

10. Shell Programming and Scripting

how to get line number of different words if exists in same line

I have some txt files. I have to create another text file which contains the portion starting from the format "Date Sex Address" to the end of the file. While using grep -n on Date it also gives me the previous line containg Date. and also Date may be DATE in some files. My file is like this... (10 Replies)
Discussion started by: Amiya Rath
10 Replies
Login or Register to Ask a Question