Line concatenation help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line concatenation help
# 1  
Old 04-10-2013
Line concatenation help

please help me on this....
Code:
cat /xx.txt
2:1
2
2:2
24
8:0
0
9:0
0

Expected result would be
Code:
2:1 2
2:2 24
8:0 0
9:0 0


Last edited by Franklin52; 04-10-2013 at 04:25 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 04-10-2013
Code:
awk '/:/ && s {print s; s=x} {s=s?s FS $0:$0} END{if(s) print s}' file

# 3  
Old 04-10-2013
Code:
awk '/:/{ORS=FS}!/:/{ORS=RS}1' file

# 4  
Old 04-10-2013
Don't forget the paste command:
Code:
paste -s -d' \n' file

# 5  
Old 04-10-2013
Other approaches:
Code:
xargs -n2 < file

Code:
paste -d' ' - - < file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenation script

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

2. UNIX for Beginners Questions & Answers

Concatenation script

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

3. Shell Programming and Scripting

Help with String concatenation

I have a script which is migrated from AIX to Linux & now while running it is no able to concatenate string values The string concatenation step under while loop is not displaying desired result Please find below the piece of code: while read EXT_FILE ; do EXT_FILE=$EXT_FILE.ext.sent echo... (7 Replies)
Discussion started by: PreetArul
7 Replies

4. Shell Programming and Scripting

String concatenation

Hi, I have two files. cat file.txt a b c d cat file1.txt j k l m I need the output as a:j (12 Replies)
Discussion started by: nareshkumar522
12 Replies

5. UNIX for Dummies Questions & Answers

Concatenation Of Variables

Hi, when I echo the values of two variables that have been set for example: export FRUIT1=ORANGE export FRUIT2=APPLE echo $FRUIT1 ORANGE echo $FRUIT2 APPLE as expected but when I echo the following: echo ${FRUIT1}AND{$FRUIT2} I was expecting to get: ORANGEANDAPPLE but... (6 Replies)
Discussion started by: jaxim
6 Replies

6. Shell Programming and Scripting

Concatenation of a line to previous line

I need to concatenate all lines of a file into 1 line. input file containing lines like 001123456400001234563 107 001578000000000000000000000000000000000000 0000000021600 001123456912345600003 107 001578000000000000000000000000000000000000 0000000992000 i am using command echo `awk... (6 Replies)
Discussion started by: reeta_shri
6 Replies

7. Shell Programming and Scripting

Sed line concatenation problem

I have a somewhat bizarre problem when trying to concatenate lines in a file. Using cat file.txt | sed -e :a -e '/$/N;s/\n/ /;ta' the output in file.txt should go from 1 2 3to 1 2 3 instead I only get the last line or 3. I find that if I open the file in gedit and hit delete in front of every... (7 Replies)
Discussion started by: pluto7777
7 Replies

8. UNIX for Dummies Questions & Answers

Recursive Concatenation

Hi, I have a problem with concatenation text files. I have a directory, say 'foo' Inside this folder, I have many sub folders, say 'oof1, oof2 .... oof20' Each oof directory has a number of text files inside it. I need to concatenate all the text files in oof directories within foo...... (1 Reply)
Discussion started by: Kerensa@unsw.ed
1 Replies

9. Shell Programming and Scripting

Concatenation

How can I do this: date = 4 -----------> 04 Month= 3-----------> 03 I wish to make a varibale named Var1 which will hold the value of current date and month value as: 2 digits for date. 2 digits for month. So finally var1 should hold value as 0403 --- MMDD (11 Replies)
Discussion started by: Asteroid
11 Replies

10. Shell Programming and Scripting

Concatenation

What is syntax for String concatenation? I have $1 as directory. $var is some variable value '/' String value. How do I have to concatenate if I have to run utility - util $1 followed by '/' followed by $var There is no space between these three. (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question