Merging lines into one


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Merging lines into one
# 1  
Old 06-18-2005
Question Merging lines into one

Hello. I would be very pleased if sb. help me to solve my problem. I've got a file with many non blank lines and I want to merge all lines into one not destroy the informations on them. I've tryed it with split and paste, tr, sed , but everything I've done has been wrong. I know about crazy solution but I don't want to do it this way. Don't forget the simplier way is the better. Thaks Smilie

Last edited by Foxgard; 06-18-2005 at 07:46 PM..
# 2  
Old 06-18-2005
tr -d '\n' < file
# 3  
Old 06-18-2005
Misunderstanding

You don't understand me. Smilie I've filled up my problem with red-coloured text to U understand me. Your solution only deletes all the newlines "\n". And that I didn't want to do with the file.
e.g.
from
A
B
C
into
ABC Smilie
# 4  
Old 06-18-2005
How is that different from deleting the newline characters?
# 5  
Old 06-19-2005
I see how you want it to work, but it doesn't work. When I send the command to bash, it deletes all the lines from input. I've had some problems with intepretation of the commands even if the command was standard before. I use the xandros 3.01,GNU bash version 2.05b.0(1)-release (i386-pc-linux-gnu). May the problem be in my OS?
# 6  
Old 06-19-2005
Code:
$ cat > test.txt
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z

Code:
#!/bin/bash
#
# append.sh
#
while read line ; do
    printf ${line}
done < $1


Code:
$ ./append.sh test.txt
abcdefghijklmnopqrstuvwxyz
$ tr -d '\n' < test.txt
abcdefghijklmnopqrstuvwxyz
$ awk '{prinf $0}' file.txt
abcdefghijklmnopqrstuvwxyz

# 7  
Old 06-19-2005
Data

Code:
bash:cat /tmp/test$$ -prints this
#define hcv 54
 #define f 8
  #define s 354
 jae
 feh
  h
  f*h
  adssfh

#the whole code isn't necessary to read only the output of cat /tmp/test2$$ and output of file$$
Code:
bash:sed "/#define.*/w /tmp/test$$" test ; sed '{s_[/t ]*#define[\t ]\+\(\<.\+\>\)[\t ]\+\(\<.\+\>\)_\{s/\1/\2/\};_}' /tmp/test$$ > /tmp/test2$$ ; cat /tmp/test2$$ | tr -d '\n' > file$$; cat file$$ -prints nothing
bash:cat /tmp/test2$$ - prints that should print
{s/hcv/54/};
{s/f/8/};
{s/s/354/};

This is the whole problem I've got and I don't understand why It doesn't work
*mistake by rewriting the code to here, because I read in my code the name of the file from $prom, now it is right

Last edited by Foxgard; 06-19-2005 at 08:34 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merging two lines into one (awk)

Hi, I am attempting to merge the following lines which run over two lines using awk. INITIAL OUTPUT 2019 Sep 28 10:47:24.695 hkaet9612 last message repeated 1 time 2019 Sep 28 10:47:24.695 hkaet9612 %ETHPORT-5-IF_DOWN_INTERFACE_REMOVED: Interfa ce Ethernet1/45 is down (Interface removed)... (10 Replies)
Discussion started by: sand1234
10 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

Merging multiple lines

I do have a text file with multiple lines on it. I want to put the lines of text into a single line where ever there is ";" for example ert, ryt, yvig, fgr; rtyu, hjk, uio, hyu, hjo; ghj, tyu, gho, hjp, jklo, kol; The resultant file I would like to have is ert, ryt, yvig, fgr;... (2 Replies)
Discussion started by: Kanja
2 Replies

4. Shell Programming and Scripting

Merging 2 lines together

I have a small problem, which due to my lack of knowledge, has left me unable to decipher some of the solutions that I looked at on these forums. So below is a piece of text, which I ran via cat -vet, which comes from within a program file. I have many such programs to process and repeatable,... (4 Replies)
Discussion started by: skarnm
4 Replies

5. Shell Programming and Scripting

Merging lines

Thanks it worked for me. I have one more question on top of that. We had few records which were splitted in 2 lines instead of one. Now i identified those lines. The file is too big to open via vi and edit it. How can i do it without opening the file. Suppose, I want line number 1001 & 1002 to... (2 Replies)
Discussion started by: Gangadhar Reddy
2 Replies

6. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

7. Shell Programming and Scripting

Merging lines

Hi folks. Could somebody help me write a script or command that will look through a file and for every line that doesn't contain a certain value, merge it with the one above? For example, the file contains: SCOTLAND|123|ABC|yes SCOTLAND|456|DEF|yes SCOTLAND|78 9|GHI|yes ... (3 Replies)
Discussion started by: MDM
3 Replies

8. Shell Programming and Scripting

Conditional merging of lines

I have a large file where some lines have been split into two lines; some of them even with white spaces before the second line. e.g in the following text I want to merge only specific lines ( say UNIX is cool), also removing white spaces only between them, others shall remain same on the output.... (4 Replies)
Discussion started by: sunny23
4 Replies

9. Shell Programming and Scripting

Merging lines in a file

Hi, I want to merge the lines starting with a comma symbol with the previous line of the file. Input : cat file.txt name1,name2 ,name3,name4 emp1,emp2,emp3 ,emp4 ,emp5 user1,user2 ,user3 Output name1,name2,name3,name4 emp1,emp2,emp3,emp4,emp5 (9 Replies)
Discussion started by: mohan_tuty
9 Replies

10. UNIX for Dummies Questions & Answers

merging two lines in a file

Hi All, I want to merge two lines in a file till the end of the file. So what could be the command to get so. say file name : sample.txt contents: country=1 send apps =1 rece=2 country=2 send apps =3 rece=3 .. ... output: country=1;send apps =1 rece=2 country=2;send apps =3... (6 Replies)
Discussion started by: thaduka
6 Replies
Login or Register to Ask a Question