concat any two lines in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers concat any two lines in a file
# 8  
Old 05-08-2012
It only prints one newline, at the very end, so no, that's not going to work for printing more than one line.

You can't go back in time to print line x after you've printed line x+1.

When you've got lots of lines out of order like that, there's pretty much only one thing to do; store everything so you can print out of order.

Working on it.

Last edited by Corona688; 05-08-2012 at 07:09 PM..
# 9  
Old 05-08-2012
Code:
$ cat ll.awk

BEGIN { C=split(LINES, A); }
NR==FNR { D[NR]=$0; next }
END {
        for(N=1; N<=COUNT; N++)
        {
                printf("%s", D[A[1]++]);
                for(X=2; X<=C; X++)
                        printf("\t%s", D[A[X]++]);

                printf("\n");
        }
}

$ head lines
line-1
line-2
line-3
line-4
line-5
line-6
line-7
line-8
line-9
line-10

$ awk -v COUNT=4 -v LINES="4 237 470 703 936 1169 1402" -f ll.awk lines
line-4  line-237        line-470        line-703        line-936        line-1169       line-1402
line-5  line-238        line-471        line-704        line-937        line-1170       line-1403
line-6  line-239        line-472        line-705        line-938        line-1171       line-1404
line-7  line-240        line-473        line-706        line-939        line-1172       line-1405

$


Last edited by Corona688; 05-08-2012 at 07:12 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concat name

Hi, I need help to combine the first 7 character of firstname if it is longer than 7and combine with the first character of lastname. ex: username lastname => usernaml user lastname => userl Thanks in advance. (10 Replies)
Discussion started by: xitrum
10 Replies

2. Shell Programming and Scripting

awk concat lines between 2 sequent digits

I would like to print string between two sequent digits and concatenate it into one single line. input.txt 99 cord, rope, strand, twine, twist, 100 strand, twine, twist, cord, rope 101 strand, twine, twist, twine, twist, cord, rope 105 cord, rope ,twi ... (8 Replies)
Discussion started by: sdf
8 Replies

3. Shell Programming and Scripting

Concat

Hi All, My Input file contains: Input.txt Name|Marks ABC|10 GHI|10 JKL|20 MNO|20 PQR|30 Output.txt MARKS|NAME 10|ABC,GHI 20|JKL,MNO 30|PQR Thanks in advance (4 Replies)
Discussion started by: kmsekhar
4 Replies

4. Shell Programming and Scripting

Need help in concat of two lines in a file

Hi , Need help in concating two lines based on certain character, for example my file has the messages : :57A:qweqweww :58A:qeqewqeqe -}$ {1:fffff2232323}{2:123123dasds}{4: :20:121323232323232 :21:sdsadasdasddadad if the line ends with "-}$" or if a line starts with "{1:" then it... (5 Replies)
Discussion started by: ulin
5 Replies

5. Shell Programming and Scripting

How to concat lines that have the same key field

Hi, I have file like this - ABC 123 ABC 456 ABC 321 CDE 789 CDE 345 FGH 111 FGH 222 FGH 333 XYZ 678 I need the output like this: ABC 123,456 CDE 789,345 FGH 111, 222 XYZ 678 Meaning I want to concat the lines that have the same first column, but I only need the first two... (10 Replies)
Discussion started by: redwing
10 Replies

6. Programming

Concat of two html file

By launching two SQL scripts I get two html files report_1.html and report_2.html with different background and text colors (white/blue for the former and silver/black for the latter) but if I try to concat the two html by using the CAT function on UNIX Server where Oracle is installed (cat... (1 Reply)
Discussion started by: Mark1970
1 Replies

7. Shell Programming and Scripting

Conditional concat lines awk

Hello, I have a text file like this: NONE FILE_Rename frompath: /log_audit/AIX/log/current/AIXAFTPP.log NONE FILE_Unlink filename /audit/tempfile.14041142 NONE FILE_Rename ... (8 Replies)
Discussion started by: carloskl
8 Replies

8. Shell Programming and Scripting

concat 6 files in 1 file ( maybe use AWK?)

hi, I have the following problem: - 6 different files that have one key in common. - this six files must be aggregated in one output file sorted by the key. - the main file has to be writen twice, one in the beggining of the new output file and another in the end, for each key. - add one... (3 Replies)
Discussion started by: naoseionome
3 Replies

9. UNIX for Dummies Questions & Answers

Search and then concat 4m other file (comma seperated)

My query is now a bit simplified. file1.txt names; ID; value1 ; values N; ABC; 1 ; a18 ; ... CDF; 2 ; b16 ; .. ABC; 1 ; c13 ; ...... EFG; 3 ;d12 ; ... file2.txt ID(Unique);smVals; smVal1; smVal N; 1; ...; ...; ...; 2; ..; ..; ..; 3; ..; ..; ..; ... (1 Reply)
Discussion started by: szchmaltz
1 Replies

10. Shell Programming and Scripting

Concat

HI all, How to concat two strings in Shell scrpits suppose x=a y=b i want to display it as ab How to do it ? Thanks.. (1 Reply)
Discussion started by: dhananjaysk
1 Replies
Login or Register to Ask a Question