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
# 1  
Old 05-08-2012
concat any two lines in a file

I have a file with line 4 : F SITE SPA_M2 SPA_M3 SPA_M4
and a line 237 with: BV_N4 VbdGO_PW Rs_NW_STI Rc_N+OD

need a awk liner to concat the two lines so that line 2 sits next to line1 and looks like:
Code:
F SITE    SPA_M2      SPA_M3      SPA_M4 BV_N4       VbdGO_PW    Rs_NW_STI   Rc_N+OD

Smilie

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 05-08-2012 at 05:49 PM..
# 2  
Old 05-08-2012
Should lines 4 and 237 be also printed in their original spots?
# 3  
Old 05-08-2012
just the contents.. I just picked two random lines so that the awk liner can be repeated for any two lines.

Smilie
# 4  
Old 05-08-2012
Code:
awk 'NR==4||NR==237{printf $0" "}END{printf "\n"}' file

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 05-08-2012
Thanks much.....

---------- Post updated at 02:16 PM ---------- Previous update was at 01:31 PM ----------

In the liner below, will a FOR statement replace to increment NR=4 to NR=237 by 1 and other NR values by 1 as well ?
Code:
awk 'NR==4||NR==237||NR==470||NR==703||NR==936||NR==1169||NR==1402{printf $0" "}END{printf "\n"}' dot >> dotpoint

Smilie

Last edited by radoulov; 05-08-2012 at 05:48 PM..
# 6  
Old 05-08-2012
I don't get what do you want for loop to do. Do you want to create statement like this?
Code:
awk 'NR==5||NR==238||NR==471||NR==704||NR==937||NR==1170||NR==1407{printf $0" "}END{printf "\n"}' dot >> dotpoint

# 7  
Old 05-08-2012
I'm looking to print line 4 which is concat version of line4+line237+line470+line703+line936+line1169+line1402, and I want to repeat this again for line 5 to line 237. It looks like this

Code:
line4+line237+line470+line703+line936+line1169+line1402
line5+line238+line471+line704+line937+line1170+line1403
and so on....

---------- Post updated at 04:16 PM ---------- Previous update was at 03:42 PM ----------

do you see an error with this ?

awk '{for (i=4; i<=236; i++)NR==i||NR==i+233||NR==i+466||NR==i+699||NR==i+932||NR==i+1165||NR==i+1398{printf $0" "}END{printf "\n"}}' try >>data

Last edited by radoulov; 05-08-2012 at 05:48 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